-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathNamespace.qll
More file actions
46 lines (38 loc) · 1.4 KB
/
Namespace.qll
File metadata and controls
46 lines (38 loc) · 1.4 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
/**
* Provides the `Namespace` class to represent .Net namespaces.
*/
private import Declaration
/** A namespace. */
class Namespace extends Declaration, @namespace {
/**
* Gets the parent namespace, if any. For example the parent namespace of `System.IO`
* is `System`. The parent namespace of `System` is the global namespace.
*/
Namespace getParentNamespace() { none() }
/**
* Gets a child namespace, if any. For example `System.IO` is a child in
* the namespace `System`.
*/
Namespace getAChildNamespace() { result.getParentNamespace() = this }
/**
* Holds if this namespace has the qualified name `qualifier`.`name`.
*
* For example if the qualified name is `System.Collections.Generic`, then
* `qualifier`=`System.Collections` and `name`=`Generic`.
*/
override predicate hasQualifiedName(string qualifier, string name) {
qualifier = this.getParentNamespace().getQualifiedName() and
name = this.getName()
}
/** Gets a textual representation of this namespace. */
override string toString() { result = this.getQualifiedName() }
/** Holds if this is the global namespace. */
final predicate isGlobalNamespace() { getName() = "" }
}
/** The global namespace. */
class GlobalNamespace extends Namespace {
GlobalNamespace() { this.getName() = "" }
override predicate hasQualifiedName(string qualifier, string name) {
qualifier = "" and name = ""
}
}