forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElement.qll
More file actions
executable file
·69 lines (60 loc) · 1.94 KB
/
Element.qll
File metadata and controls
executable file
·69 lines (60 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* Provides a class that represents named elements in Java programs.
*/
import CompilationUnit
import semmle.code.Location
import Javadoc
/** A program element that has a name. */
class Element extends @element, Top {
/** Holds if this element has the specified `name`. */
predicate hasName(string name) { hasName(this, name) }
/** Gets the name of this element. */
string getName() { this.hasName(result) }
/**
* Holds if this element transitively contains the specified element `e`.
*/
predicate contains(Element e) { this.hasChildElement+(e) }
/**
* Holds if this element is the immediate parent of the specified element `e`.
*
* It is usually preferable to use more specific predicates such as
* `getEnclosingCallable()`, `getDeclaringType()` and/or `getEnclosingType()`
* instead of this general predicate.
*/
predicate hasChildElement(Element e) { hasChildElement(this, e) }
/**
* Holds if this element pertains to a source file.
*
* Elements pertaining to source files may include generated elements
* not visible in source code, such as implicit default constructors.
*/
predicate fromSource() { getCompilationUnit().getExtension() = "java" }
/** Gets the compilation unit that this element belongs to. */
CompilationUnit getCompilationUnit() { result = getFile() }
/** Cast this element to a `Documentable`. */
Documentable getDoc() { result = this }
}
/**
* Holds if element `parent` is immediately above element `e` in the syntax tree.
*/
private predicate hasChildElement(Element parent, Element e) {
cupackage(e, parent)
or
enclInReftype(e, parent)
or
not enclInReftype(e, _) and
e.(Class).getCompilationUnit() = parent
or
not enclInReftype(e, _) and
e.(Interface).getCompilationUnit() = parent
or
methods(e, _, _, _, parent, _)
or
constrs(e, _, _, _, parent, _)
or
params(e, _, _, parent, _)
or
fields(e, _, _, parent, _)
or
typeVars(e, _, _, _, parent)
}