1
1
/** Provides classes for namespaces. */
2
2
3
+ private import semmle.code.csharp.commons.QualifiedName
3
4
import Element
4
5
import Type
5
6
private import dotnet
@@ -18,24 +19,44 @@ class TypeContainer extends Declaration, @type_container { }
18
19
* }
19
20
* ```
20
21
*/
21
- class Namespace extends DotNet :: Namespace , TypeContainer , Declaration , @namespace {
22
+ class Namespace extends TypeContainer , Declaration , @namespace {
22
23
override Namespace getParent ( ) { result = this .getParentNamespace ( ) }
23
24
24
- override Namespace getParentNamespace ( ) { parent_namespace ( this , result ) }
25
+ /**
26
+ * Gets the parent namespace, if any. For example the parent namespace of `System.IO`
27
+ * is `System`. The parent namespace of `System` is the global namespace.
28
+ */
29
+ Namespace getParentNamespace ( ) { parent_namespace ( this , result ) }
25
30
26
- override Namespace getAChildNamespace ( ) { parent_namespace ( result , this ) }
31
+ /**
32
+ * Gets a child namespace, if any. For example `System.IO` is a child in
33
+ * the namespace `System`.
34
+ */
35
+ Namespace getAChildNamespace ( ) { parent_namespace ( result , this ) }
27
36
28
37
override TypeContainer getChild ( int i ) {
29
38
i = 0 and
30
39
parent_namespace ( result , this )
31
40
}
32
41
42
+ /**
43
+ * Holds if this namespace has the qualified name `qualifier`.`name`.
44
+ *
45
+ * For example if the qualified name is `System.Collections.Generic`, then
46
+ * `qualifier`=`System.Collections` and `name`=`Generic`.
47
+ */
33
48
deprecated override predicate hasQualifiedName ( string qualifier , string name ) {
34
- DotNet :: Namespace . super . hasQualifiedName ( qualifier , name )
49
+ namespaceHasQualifiedName ( this , qualifier , name )
35
50
}
36
51
52
+ /**
53
+ * Holds if this namespace has the qualified name `qualifier`.`name`.
54
+ *
55
+ * For example if the qualified name is `System.Collections.Generic`, then
56
+ * `qualifier`=`System.Collections` and `name`=`Generic`.
57
+ */
37
58
override predicate hasFullyQualifiedName ( string qualifier , string name ) {
38
- DotNet :: Namespace . super . hasFullyQualifiedName ( qualifier , name )
59
+ namespaceHasQualifiedName ( this , qualifier , name )
39
60
}
40
61
41
62
/**
@@ -123,7 +144,28 @@ class Namespace extends DotNet::Namespace, TypeContainer, Declaration, @namespac
123
144
124
145
override Location getALocation ( ) { result = this .getADeclaration ( ) .getALocation ( ) }
125
146
126
- override string toString ( ) { result = DotNet:: Namespace .super .toString ( ) }
147
+ /** Gets a textual representation of this namespace. */
148
+ override string toString ( ) { result = this .getFullName ( ) }
149
+
150
+ /** Holds if this is the global namespace. */
151
+ final predicate isGlobalNamespace ( ) { this .getName ( ) = "" }
152
+
153
+ /** Gets the simple name of this namespace, for example `IO` in `System.IO`. */
154
+ final override string getName ( ) { namespaces ( this , result ) }
155
+
156
+ final override string getUndecoratedName ( ) { namespaces ( this , result ) }
157
+
158
+ override string getAPrimaryQlClass ( ) { result = "Namespace" }
159
+
160
+ /**
161
+ * Get the fully qualified name of this namespace.
162
+ */
163
+ string getFullName ( ) {
164
+ exists ( string namespace , string name |
165
+ namespaceHasQualifiedName ( this , namespace , name ) and
166
+ result = getQualifiedName ( namespace , name )
167
+ )
168
+ }
127
169
}
128
170
129
171
/**
0 commit comments