Skip to content

Commit b72f345

Browse files
committed
C#: Use {get,has}FullyQualifiedName throughout
1 parent 66dc550 commit b72f345

File tree

242 files changed

+565
-517
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

242 files changed

+565
-517
lines changed

csharp/ql/examples/snippets/catch_exception.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
import csharp
1111

1212
from CatchClause catch
13-
where catch.getCaughtExceptionType().hasQualifiedName("System.IO", "IOException")
13+
where catch.getCaughtExceptionType().hasFullyQualifiedName("System.IO", "IOException")
1414
select catch

csharp/ql/examples/snippets/constructor_call.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
import csharp
1111

1212
from ObjectCreation new
13-
where new.getObjectType().hasQualifiedName("System", "Exception")
13+
where new.getObjectType().hasFullyQualifiedName("System", "Exception")
1414
select new

csharp/ql/examples/snippets/extend_class.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
import csharp
1414

1515
from RefType type
16-
where type.getABaseType+().hasQualifiedName("System.Collections", "IEnumerator")
16+
where type.getABaseType+().hasFullyQualifiedName("System.Collections", "IEnumerator")
1717
select type

csharp/ql/examples/snippets/field_read.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ import csharp
1111
from Field f, FieldRead read
1212
where
1313
f.hasName("VirtualAddress") and
14-
f.getDeclaringType().hasQualifiedName("Mono.Cecil.PE", "Section") and
14+
f.getDeclaringType().hasFullyQualifiedName("Mono.Cecil.PE", "Section") and
1515
f = read.getTarget()
1616
select read

csharp/ql/examples/snippets/method_call.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ from MethodCall call, Method method
1212
where
1313
call.getTarget() = method and
1414
method.hasName("MethodName") and
15-
method.getDeclaringType().hasQualifiedName("Company", "Class")
15+
method.getDeclaringType().hasFullyQualifiedName("Company", "Class")
1616
select call

csharp/ql/examples/snippets/null_argument.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ where
1717
add.hasName("Add") and
1818
add.getDeclaringType()
1919
.getUnboundDeclaration()
20-
.hasQualifiedName("System.Collections.Generic", "ICollection<>") and
20+
.hasFullyQualifiedName("System.Collections.Generic", "ICollection`1") and
2121
call.getAnArgument() instanceof NullLiteral
2222
select call

csharp/ql/examples/snippets/override_method.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ import csharp
1111
from Method override, Method base
1212
where
1313
base.hasName("ToString") and
14-
base.getDeclaringType().hasQualifiedName("System", "Object") and
14+
base.getDeclaringType().hasFullyQualifiedName("System", "Object") and
1515
base.getAnOverrider() = override
1616
select override

csharp/ql/examples/snippets/throw_exception.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
import csharp
1010

1111
from ThrowStmt throw
12-
where throw.getThrownExceptionType().getBaseClass*().hasQualifiedName("System.IO", "IOException")
12+
where
13+
throw.getThrownExceptionType().getBaseClass*().hasFullyQualifiedName("System.IO", "IOException")
1314
select throw

csharp/ql/integration-tests/all-platforms/diag_recursive_generics/Types.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import csharp
22

33
from Class c
44
where c.fromSource()
5-
select c, c.getBaseClass().getQualifiedName()
5+
select c, c.getBaseClass().getFullyQualifiedName()

csharp/ql/lib/Linq/Helpers.qll

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ private int numStmts(ForeachStmt fes) {
2121
}
2222

2323
/** Holds if the type's qualified name is "System.Linq.Enumerable" */
24-
predicate isEnumerableType(ValueOrRefType t) { t.hasQualifiedName("System.Linq", "Enumerable") }
24+
predicate isEnumerableType(ValueOrRefType t) {
25+
t.hasFullyQualifiedName("System.Linq", "Enumerable")
26+
}
2527

2628
/** Holds if the type's qualified name starts with "System.Collections.Generic.IEnumerable" */
2729
predicate isIEnumerableType(ValueOrRefType t) {
2830
exists(string type |
29-
t.hasQualifiedName("System.Collections.Generic", type) and
31+
t.hasFullyQualifiedName("System.Collections.Generic", type) and
3032
type.matches("IEnumerable%")
3133
)
3234
}
@@ -159,7 +161,7 @@ class AnyCall extends MethodCall {
159161
exists(Method m |
160162
m = this.getTarget().getUnboundDeclaration() and
161163
isEnumerableType(m.getDeclaringType()) and
162-
m.hasName("Any<>")
164+
m.hasName("Any`1")
163165
)
164166
}
165167
}
@@ -170,7 +172,7 @@ class CountCall extends MethodCall {
170172
exists(Method m |
171173
m = this.getTarget().getUnboundDeclaration() and
172174
isEnumerableType(m.getDeclaringType()) and
173-
m.hasName("Count<>")
175+
m.hasName("Count`1")
174176
)
175177
}
176178
}
@@ -186,7 +188,7 @@ class SelectCall extends ExtensionMethodCall {
186188
exists(Method m |
187189
m = this.getTarget().getUnboundDeclaration() and
188190
isEnumerableType(m.getDeclaringType()) and
189-
m.hasName("Select<,>")
191+
m.hasName("Select`2")
190192
)
191193
}
192194

csharp/ql/lib/semmle/code/asp/AspNet.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class PageDirective extends AspDirective {
186186
*/
187187
ValueOrRefType getInheritedType() {
188188
exists(string qualifier, string type |
189-
result.hasQualifiedName(qualifier, type) and
189+
result.hasFullyQualifiedName(qualifier, type) and
190190
splitQualifiedName(this.getInheritedTypeQualifiedName(), qualifier, type)
191191
)
192192
}

csharp/ql/lib/semmle/code/cil/ConsistencyChecks.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ class InvalidOverride extends MethodViolation {
486486

487487
override string getMessage() {
488488
exists(string qualifier, string type |
489-
base.getDeclaringType().hasQualifiedName(qualifier, type)
489+
base.getDeclaringType().hasFullyQualifiedName(qualifier, type)
490490
|
491491
result =
492492
"Overridden method from " + getQualifiedName(qualifier, type) + " is not in a base type"

csharp/ql/lib/semmle/code/cil/Method.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class Method extends DotNet::Callable, Element, Member, TypeContainer, DataFlowN
147147

148148
/** Holds if this method is a destructor/finalizer. */
149149
predicate isFinalizer() {
150-
this.getOverriddenMethod*().hasQualifiedName("System", "Object", "Finalize")
150+
this.getOverriddenMethod*().hasFullyQualifiedName("System", "Object", "Finalize")
151151
}
152152

153153
/** Holds if this method is an operator. */
@@ -259,7 +259,7 @@ class Setter extends Accessor {
259259

260260
/** Holds if this setter is an `init` accessor. */
261261
predicate isInitOnly() {
262-
exists(Type t | t.hasQualifiedName("System.Runtime.CompilerServices", "IsExternalInit") |
262+
exists(Type t | t.hasFullyQualifiedName("System.Runtime.CompilerServices", "IsExternalInit") |
263263
this.hasRequiredCustomModifier(t)
264264
)
265265
}

csharp/ql/lib/semmle/code/csharp/Generics.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private string getTypeArgumentsNames(ConstructedGeneric cg) {
103103

104104
/**
105105
* An unbound generic type. This is a generic type with type parameters
106-
* (for example `List<T>`) or elided type parameters (for example `List<>`).
106+
* (for example `List<T>`) or elided type parameters (for example ``List`1``).
107107
*
108108
* Either an unbound generic `struct` (`UnboundGenericStruct`), an unbound generic `class`
109109
* (`UnboundGenericClass`), an unbound generic `interface` (`UnboundGenericInterface`), or

csharp/ql/lib/semmle/code/csharp/PrintAst.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ private ValueOrRefType getAnInterestingBaseType(ValueOrRefType type) {
107107

108108
private predicate isInterestingBaseType(ValueOrRefType type, ValueOrRefType base) {
109109
not base instanceof ObjectType and
110-
not base.hasQualifiedName("System", "ValueType") and
111-
not base.hasQualifiedName("System", "Delegate") and
112-
not base.hasQualifiedName("System", "MulticastDelegate") and
113-
not base.hasQualifiedName("System", "Enum") and
110+
not base.hasFullyQualifiedName("System", "ValueType") and
111+
not base.hasFullyQualifiedName("System", "Delegate") and
112+
not base.hasFullyQualifiedName("System", "MulticastDelegate") and
113+
not base.hasFullyQualifiedName("System", "Enum") and
114114
exists(TypeMention tm | tm.getTarget() = type and tm.getType() = base)
115115
}
116116

csharp/ql/lib/semmle/code/csharp/Stmt.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class BlockStmt extends Stmt, @block_stmt {
7575

7676
/** Holds if this block is the container of the global statements. */
7777
predicate isGlobalStatementContainer() {
78-
this.getEnclosingCallable().hasQualifiedName("Program", "<Main>$")
78+
this.getEnclosingCallable().hasFullyQualifiedName("Program", "<Main>$")
7979
}
8080

8181
override Stmt stripSingletonBlocks() {

csharp/ql/lib/semmle/code/csharp/Type.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class ValueOrRefType extends DotNet::ValueOrRefType, Type, Attributable, @value_
287287

288288
/** Gets the length of *some* path to the root of the hierarchy. */
289289
int getADepth() {
290-
this.hasQualifiedName("System", "Object") and result = 0
290+
this.hasFullyQualifiedName("System", "Object") and result = 0
291291
or
292292
result = this.getABaseType().getADepth() + 1 and
293293
//prevent recursion on cyclic inheritance (only for incorrect databases)
@@ -809,7 +809,7 @@ class AnonymousClass extends Class {
809809
* The `object` type, `System.Object`.
810810
*/
811811
class ObjectType extends Class {
812-
ObjectType() { this.hasQualifiedName("System", "Object") }
812+
ObjectType() { this.hasFullyQualifiedName("System", "Object") }
813813

814814
override string toStringWithTypes() { result = "object" }
815815

@@ -820,7 +820,7 @@ class ObjectType extends Class {
820820
* The `string` type, `System.String`.
821821
*/
822822
class StringType extends Class {
823-
StringType() { this.hasQualifiedName("System", "String") }
823+
StringType() { this.hasFullyQualifiedName("System", "String") }
824824

825825
override string toStringWithTypes() { result = "string" }
826826

@@ -994,7 +994,7 @@ class NullableType extends ValueType, ConstructedType, @nullable_type {
994994
}
995995

996996
override UnboundGenericStruct getUnboundGeneric() {
997-
result.hasQualifiedName("System", "Nullable<>")
997+
result.hasFullyQualifiedName("System", "Nullable`1")
998998
}
999999

10001000
override string toStringWithTypes() {

csharp/ql/lib/semmle/code/csharp/commons/Collections.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,22 @@ private string genericCollectionNamespaceName() {
4545
private string genericCollectionTypeName() {
4646
result =
4747
[
48-
"Dictionary<,>", "HashSet<>", "ICollection<>", "IDictionary<,>", "IList<>", "ISet<>",
49-
"LinkedList<>", "List<>", "Queue<>", "SortedDictionary<,>", "SortedList<,>", "SortedSet<>",
50-
"Stack<>", "SynchronizedCollection<>", "SynchronizedKeyedCollection<>",
51-
"SynchronizedReadOnlyCollection<>"
48+
"Dictionary`2", "HashSet`1", "ICollection`1", "IDictionary`2", "IList`1", "ISet`1",
49+
"LinkedList`1", "List`1", "Queue`1", "SortedDictionary`2", "SortedList`2", "SortedSet`1",
50+
"Stack`1", "SynchronizedCollection`1", "SynchronizedKeyedCollection`1",
51+
"SynchronizedReadOnlyCollection`1"
5252
]
5353
}
5454

5555
/** A collection type. */
5656
class CollectionType extends RefType {
5757
CollectionType() {
5858
exists(RefType base | base = this.getABaseType*() |
59-
base.hasQualifiedName(collectionNamespaceName(), collectionTypeName())
59+
base.hasFullyQualifiedName(collectionNamespaceName(), collectionTypeName())
6060
or
6161
base.(ConstructedType)
6262
.getUnboundGeneric()
63-
.hasQualifiedName(genericCollectionNamespaceName(), genericCollectionTypeName())
63+
.hasFullyQualifiedName(genericCollectionNamespaceName(), genericCollectionTypeName())
6464
)
6565
or
6666
this instanceof ArrayType

csharp/ql/lib/semmle/code/csharp/commons/TargetFramework.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class TargetFrameworkAttribute extends Attribute {
1414
Assembly assembly;
1515

1616
TargetFrameworkAttribute() {
17-
this.getType().hasQualifiedName("System.Runtime.Versioning", "TargetFrameworkAttribute") and
17+
this.getType().hasFullyQualifiedName("System.Runtime.Versioning", "TargetFrameworkAttribute") and
1818
assembly = this.getTarget()
1919
}
2020

csharp/ql/lib/semmle/code/csharp/commons/Util.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class MainMethod extends Method {
88
(
99
this.hasName("Main")
1010
or
11-
this.hasQualifiedName("Program", "<Main>$")
11+
this.hasFullyQualifiedName("Program", "<Main>$")
1212
) and
1313
this.isStatic() and
1414
(this.getReturnType() instanceof VoidType or this.getReturnType() instanceof IntType) and

csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ module Expressions {
780780
nc.getOuterCompletion()
781781
.(ThrowCompletion)
782782
.getExceptionClass()
783-
.hasQualifiedName("System", "InvalidOperationException")
783+
.hasFullyQualifiedName("System", "InvalidOperationException")
784784
)
785785
)
786786
}

csharp/ql/lib/semmle/code/csharp/controlflow/internal/NonReturning.qll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ private class ThrowingCall extends NonReturningCall {
5151
this =
5252
any(MethodCall mc |
5353
mc.getTarget()
54-
.hasQualifiedName("System.Runtime.ExceptionServices", "ExceptionDispatchInfo", "Throw") and
54+
.hasFullyQualifiedName("System.Runtime.ExceptionServices", "ExceptionDispatchInfo",
55+
"Throw") and
5556
(
5657
mc.hasNoArguments() and
5758
c.getExceptionClass() instanceof SystemExceptionClass
@@ -85,8 +86,8 @@ private class DirectlyExitingCallable extends ExitingCallable {
8586
DirectlyExitingCallable() {
8687
this =
8788
any(Method m |
88-
m.hasQualifiedName("System", "Environment", "Exit") or
89-
m.hasQualifiedName("System.Windows.Forms", "Application", "Exit")
89+
m.hasFullyQualifiedName("System", "Environment", "Exit") or
90+
m.hasFullyQualifiedName("System.Windows.Forms", "Application", "Exit")
9091
)
9192
}
9293
}

csharp/ql/lib/semmle/code/csharp/dataflow/internal/FlowSummaryImplSpecific.qll

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,21 @@ SummaryComponent interpretComponentSpecific(AccessPathToken c) {
174174
or
175175
c = "WithElement" and result = SummaryComponent::withContent(any(ElementContent ec))
176176
or
177+
// Qualified names may contain commas,such as in `Tuple<,>`, so get the entire argument list
178+
// rather than an individual argument.
177179
exists(Field f |
178-
c.getAnArgument("Field") = f.getFullyQualifiedName() and
180+
c.getName() = "Field" and
181+
c.getArgumentList() = f.getFullyQualifiedName() and
179182
result = SummaryComponent::content(any(FieldContent fc | fc.getField() = f))
180183
)
181184
or
182185
exists(Property p |
183-
184-
c.getAnArgument("Property") = p.getFullyQualifiedName() and
186+
c.getName() = "Property" and
187+
c.getArgumentList() = p.getFullyQualifiedName() and
185188
result = SummaryComponent::content(any(PropertyContent pc | pc.getProperty() = p))
186189
)
187190
or
188191
exists(SyntheticField f |
189-
190192
c.getAnArgument("SyntheticField") = f and
191193
result = SummaryComponent::content(any(SyntheticFieldContent sfc | sfc.getField() = f))
192194
)
@@ -198,7 +200,9 @@ private string getContentSpecific(Content c) {
198200
or
199201
exists(Field f | c = TFieldContent(f) and result = "Field[" + f.getFullyQualifiedName() + "]")
200202
or
201-
exists(Property p | c = TPropertyContent(p) and result = "Property[" + p.getFullyQualifiedName() + "]")
203+
exists(Property p |
204+
c = TPropertyContent(p) and result = "Property[" + p.getFullyQualifiedName() + "]"
205+
)
202206
or
203207
exists(SyntheticField f | c = TSyntheticFieldContent(f) and result = "SyntheticField[" + f + "]")
204208
}

csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/RangeUtils.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private module Impl {
152152
*/
153153
predicate propertyOverrides(Property p, string namespace, string baseClass, string property) {
154154
exists(Property p2 |
155-
p2.getUnboundDeclaration().getDeclaringType().hasQualifiedName(namespace, baseClass) and
155+
p2.getUnboundDeclaration().getDeclaringType().hasFullyQualifiedName(namespace, baseClass) and
156156
p2.hasName(property)
157157
|
158158
p.overridesOrImplementsOrEquals(p2)

csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/SignAnalysisSpecific.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private module Impl {
8383
*/
8484
predicate containerSizeAccess(ExprNode e) {
8585
exists(Property p | p = e.getExpr().(PropertyAccess).getTarget() |
86-
propertyOverrides(p, "System.Collections.Generic", "IEnumerable<>", "Count") or
86+
propertyOverrides(p, "System.Collections.Generic", "IEnumerable`1", "Count") or
8787
propertyOverrides(p, "System.Collections", "ICollection", "Count") or
8888
propertyOverrides(p, "System", "String", "Length") or
8989
propertyOverrides(p, "System", "Array", "Length")

0 commit comments

Comments
 (0)