Skip to content

Commit 38e906f

Browse files
committed
C#: Use hasQualifiedName instead of getQualifiedName.
1 parent c24302b commit 38e906f

File tree

51 files changed

+278
-226
lines changed

Some content is hidden

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

51 files changed

+278
-226
lines changed

csharp/ql/lib/Linq/Helpers.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ predicate isEnumerableType(ValueOrRefType t) { t.hasQualifiedName("System.Linq",
2323

2424
/** Holds if the type's qualified name starts with "System.Collections.Generic.IEnumerable" */
2525
predicate isIEnumerableType(ValueOrRefType t) {
26-
t.getQualifiedName().matches("System.Collections.Generic.IEnumerable%")
26+
exists(string type |
27+
t.hasQualifiedName("System.Collections.Generic", type) and
28+
type.matches("IEnumerable%")
29+
)
2730
}
2831

2932
/**

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

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class AspAttribute extends AspElement, @asp_attribute { }
4040
*/
4141
class AspOpenTag extends AspElement, @asp_open_tag {
4242
/** Either `>` or `/>`, depending on whether it's an empty tag. */
43-
private string closeAngle() { if isEmpty() then result = "/>" else result = ">" }
43+
private string closeAngle() { if this.isEmpty() then result = "/>" else result = ">" }
4444

4545
/** Gets the `i`th attribute of this open tag. */
4646
AspAttribute getAttribute(int i) { asp_tag_attribute(this, i, _, result) }
@@ -58,9 +58,9 @@ class AspOpenTag extends AspElement, @asp_open_tag {
5858
predicate isEmpty() { asp_tag_isempty(this) }
5959

6060
override string toString() {
61-
if hasAttribute()
62-
then result = "<" + getName() + " ..." + closeAngle()
63-
else result = "<" + getName() + closeAngle()
61+
if this.hasAttribute()
62+
then result = "<" + this.getName() + " ..." + this.closeAngle()
63+
else result = "<" + this.getName() + this.closeAngle()
6464
}
6565
}
6666

@@ -75,9 +75,9 @@ class AspOpenTag extends AspElement, @asp_open_tag {
7575
*/
7676
class AspCloseTag extends AspElement, @asp_close_tag {
7777
/** Gets the name of this close tag. */
78-
string getName() { result = getBody() }
78+
string getName() { result = this.getBody() }
7979

80-
override string toString() { result = "</" + getName() + ">" }
80+
override string toString() { result = "</" + this.getName() + ">" }
8181
}
8282

8383
/**
@@ -146,44 +146,49 @@ class AspDirective extends AspElement, @asp_directive {
146146
string getName() { asp_directive_name(this, result) }
147147

148148
/** Holds if this directive has an attribute. */
149-
predicate hasAttribute() { exists(getAttribute(_)) }
149+
predicate hasAttribute() { exists(this.getAttribute(_)) }
150150

151151
override string toString() {
152-
if hasAttribute()
153-
then result = "<%@" + getName() + " ...%>"
154-
else result = "<%@" + getName() + "%>"
152+
if this.hasAttribute()
153+
then result = "<%@" + this.getName() + " ...%>"
154+
else result = "<%@" + this.getName() + "%>"
155155
}
156156
}
157157

158158
/** A quoted string used as an attribute in a tag. */
159159
class AspQuotedString extends AspAttribute, @asp_quoted_string {
160160
override string toString() {
161-
if exists(getBody().indexOf("\""))
162-
then result = "'" + getBody() + "'"
163-
else result = "\"" + getBody() + "\""
161+
if exists(this.getBody().indexOf("\""))
162+
then result = "'" + this.getBody() + "'"
163+
else result = "\"" + this.getBody() + "\""
164164
}
165165
}
166166

167167
/** Arbitrary text. It will be inserted into the document as is. */
168168
class AspText extends AspElement, @asp_text {
169-
override string toString() { result = getBody() }
169+
override string toString() { result = this.getBody() }
170170
}
171171

172172
/** An XML directive, such as a `DOCTYPE` declaration. */
173173
class AspXmlDirective extends AspElement, @asp_xml_directive {
174-
override string toString() { result = getBody() }
174+
override string toString() { result = this.getBody() }
175175
}
176176

177177
/**
178178
* A 'Page' ASP directive.
179179
*/
180180
class PageDirective extends AspDirective {
181-
PageDirective() { getName() = "Page" }
181+
PageDirective() { this.getName() = "Page" }
182182

183183
/**
184184
* Gets the 'CodeBehind' class from which this page inherits.
185185
*/
186-
ValueOrRefType getInheritedType() { result.getQualifiedName() = getInheritedTypeQualifiedName() }
186+
ValueOrRefType getInheritedType() {
187+
exists(string qualifier, string name |
188+
result.hasQualifiedName(qualifier, name) and
189+
printQualifiedName(qualifier, name) = this.getInheritedTypeQualifiedName()
190+
)
191+
}
187192

188193
private string getInheritedTypeQualifiedName() {
189194
// Relevant attributes:
@@ -192,11 +197,11 @@ class PageDirective extends AspDirective {
192197
// provide a fallback namespace if `Inherits` does not have one
193198
// - `CodeBehindFile`/`CodeFile`: used by tooling, but not semantically
194199
// relevant at runtime
195-
exists(string inherits | inherits = getAttributeByName("Inherits").getBody() |
200+
exists(string inherits | inherits = this.getAttributeByName("Inherits").getBody() |
196201
if inherits.indexOf(".") != -1
197202
then result = inherits
198203
else
199-
exists(string className | className = getAttributeByName("ClassName").getBody() |
204+
exists(string className | className = this.getAttributeByName("ClassName").getBody() |
200205
// take everything up to and including the last .
201206
className.prefix(className.indexOf(".", count(className.indexOf(".")) - 1, 0) + 1) +
202207
inherits = result

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,13 @@ class InvalidOverride extends MethodViolation {
484484
}
485485

486486
override string getMessage() {
487-
result =
488-
"Overridden method from " + base.getDeclaringType().getQualifiedName() +
489-
" is not in a base type"
487+
exists(string qualifier, string name |
488+
base.getDeclaringType().hasQualifiedName(qualifier, name)
489+
|
490+
result =
491+
"Overridden method from " + CS::printQualifiedName(qualifier, name) +
492+
" is not in a base type"
493+
)
490494
}
491495
}
492496

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

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

147147
/** Holds if this method is a destructor/finalizer. */
148148
predicate isFinalizer() {
149-
this.getOverriddenMethod*().getQualifiedName() = "System.Object.Finalize"
149+
this.getOverriddenMethod*().hasQualifiedName("System", "Object", "Finalize")
150150
}
151151

152152
/** Holds if this method is an operator. */
@@ -258,7 +258,7 @@ class Setter extends Accessor {
258258

259259
/** Holds if this setter is an `init` accessor. */
260260
predicate isInitOnly() {
261-
exists(Type t | t.getQualifiedName() = "System.Runtime.CompilerServices.IsExternalInit" |
261+
exists(Type t | t.hasQualifiedName("System.Runtime.CompilerServices", "IsExternalInit") |
262262
this.hasRequiredCustomModifier(t)
263263
)
264264
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class TypeContainer extends DotNet::NamedElement, @cil_type_container {
2020

2121
/** A namespace. */
2222
class Namespace extends DotNet::Namespace, TypeContainer, @namespace {
23-
override string toString() { result = this.getQualifiedName() }
23+
override string toString() { result = this.getFullName() }
2424

2525
override Namespace getParent() { result = this.getParentNamespace() }
2626

@@ -68,8 +68,7 @@ class Type extends DotNet::Type, Declaration, TypeContainer, @cil_type {
6868

6969
/**
7070
* Holds if this type is a member of the `System` namespace and has the name
71-
* `name`. This is the same as `getQualifiedName() = "System.<name>"`, but is
72-
* faster to compute.
71+
* `name`.
7372
*/
7473
predicate isSystemType(string name) {
7574
exists(Namespace system | this.getParent() = system |

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,18 @@ private string getTypeArgumentsNames(ConstructedGeneric cg) {
9797
result = strictconcat(Type t, int i | t = cg.getTypeArgument(i) | t.getName(), "," order by i)
9898
}
9999

100-
/** Gets the concatenation of the `getQualifiedName()` of type arguments. */
100+
bindingset[t]
101+
private string getFullName(Type t) {
102+
exists(string qualifier, string name |
103+
t.hasQualifiedName(qualifier, name) and
104+
result = printQualifiedName(qualifier, name)
105+
)
106+
}
107+
108+
/** Gets the concatenation of the `getFullName` of type arguments. */
101109
language[monotonicAggregates]
102110
private string getTypeArgumentsQualifiedNames(ConstructedGeneric cg) {
103-
result =
104-
strictconcat(Type t, int i | t = cg.getTypeArgument(i) | t.getQualifiedName(), "," order by i)
111+
result = strictconcat(Type t, int i | t = cg.getTypeArgument(i) | getFullName(t), "," order by i)
105112
}
106113

107114
/**

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.getQualifiedName() = "System.ValueType" and
111-
not base.getQualifiedName() = "System.Delegate" and
112-
not base.getQualifiedName() = "System.MulticastDelegate" and
113-
not base.getQualifiedName() = "System.Enum" 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
114114
exists(TypeMention tm | tm.getTarget() = type and tm.getType() = base)
115115
}
116116

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class ValueOrRefType extends DotNet::ValueOrRefType, Type, Attributable, @value_
6969
)
7070
or
7171
not exists(this.getDeclaringType()) and
72-
qualifier = this.getNamespace().getQualifiedName() and
72+
qualifier = this.getNamespace().getFullName() and
7373
name = this.getUndecoratedName()
7474
}
7575

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class GeneratedAttributeFile extends GeneratedCodeFile {
3939
class GeneratedNamespaceFile extends GeneratedCodeFile {
4040
GeneratedNamespaceFile() {
4141
exists(Namespace n | n.getATypeDeclaration().getFile() = this |
42-
n.getQualifiedName() = "Microsoft.Xml.Serialization.GeneratedAssembly"
42+
n.getFullName() = "Microsoft.Xml.Serialization.GeneratedAssembly"
4343
)
4444
}
4545
}

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().getQualifiedName() = "System.Runtime.Versioning.TargetFrameworkAttribute" and
17+
this.getType().hasQualifiedName("System.Runtime.Versioning", "TargetFrameworkAttribute") and
1818
assembly = this.getTarget()
1919
}
2020

0 commit comments

Comments
 (0)