Skip to content

Commit 8fa9191

Browse files
committed
C#: Deprecate the getFullyQualifiedName predicate.
1 parent 2fb9c2d commit 8fa9191

File tree

7 files changed

+35
-16
lines changed

7 files changed

+35
-16
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import csharp
2+
import semmle.code.csharp.commons.QualifiedName
23

3-
from Class c
4-
where c.fromSource()
5-
select c, c.getBaseClass().getFullyQualifiedName()
4+
from Class c, string qualifier, string name
5+
where c.fromSource() and c.getBaseClass().hasFullyQualifiedName(qualifier, name)
6+
select c, getQualifiedName(qualifier, name)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ class NamedElement extends Element, @named_element {
102102
final predicate hasName(string name) { name = this.getName() }
103103

104104
/**
105+
* DEPRECATED: Use `hasFullyQualifiedName` instead.
106+
*
105107
* Gets the fully qualified name of this element, for example the
106108
* fully qualified name of `M` on line 3 is `N.C.M` in
107109
*
@@ -117,7 +119,7 @@ class NamedElement extends Element, @named_element {
117119
* ``System.Collections.Generic.IList`1``.
118120
*/
119121
cached
120-
final string getFullyQualifiedName() {
122+
deprecated final string getFullyQualifiedName() {
121123
exists(string qualifier, string name | this.hasFullyQualifiedName(qualifier, name) |
122124
if qualifier = "" then result = name else result = qualifier + "." + name
123125
)

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,12 @@ class Declaration extends NamedElement, @declaration {
8888
* ```
8989
*/
9090
string getFullyQualifiedNameWithTypes() {
91-
exists(string qual |
92-
qual = this.getDeclaringType().getFullyQualifiedName() and
91+
exists(string fullqual, string qual, string name |
92+
this.getDeclaringType().hasFullyQualifiedName(qual, name) and
93+
fullqual = getQualifiedName(qual, name) and
9394
if this instanceof NestedType
94-
then result = qual + "+" + this.toStringWithTypes()
95-
else result = qual + "." + this.toStringWithTypes()
95+
then result = fullqual + "+" + this.toStringWithTypes()
96+
else result = fullqual + "." + this.toStringWithTypes()
9697
)
9798
}
9899

csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import csharp
6+
private import semmle.code.csharp.commons.QualifiedName
67

78
/**
89
* Provides classes for working with static single assignment (SSA) form.
@@ -120,7 +121,12 @@ module Ssa {
120121
result = prefix + "." + this.getAssignable()
121122
|
122123
if f.(Modifiable).isStatic()
123-
then prefix = f.getDeclaringType().getFullyQualifiedName()
124+
then
125+
exists(string qualifier, string name |
126+
f.getDeclaringType().hasFullyQualifiedName(qualifier, name)
127+
|
128+
prefix = getQualifiedName(qualifier, name)
129+
)
124130
else prefix = "this"
125131
)
126132
}

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
private import csharp
6+
private import semmle.code.csharp.commons.QualifiedName
67
private import semmle.code.csharp.frameworks.system.linq.Expressions
78
private import codeql.dataflow.internal.FlowSummaryImpl
89
private import codeql.dataflow.internal.AccessPathSyntax as AccessPath
@@ -42,10 +43,18 @@ module Input implements InputSig<Location, DataFlowImplSpecific::CsharpDataFlow>
4243
string encodeContent(ContentSet c, string arg) {
4344
c = TElementContent() and result = "Element" and arg = ""
4445
or
45-
exists(Field f | c = TFieldContent(f) and result = "Field" and arg = f.getFullyQualifiedName())
46+
exists(Field f, string qualifier, string name |
47+
c = TFieldContent(f) and
48+
f.hasFullyQualifiedName(qualifier, name) and
49+
arg = getQualifiedName(qualifier, name) and
50+
result = "Field"
51+
)
4652
or
47-
exists(Property p |
48-
c = TPropertyContent(p) and result = "Property" and arg = p.getFullyQualifiedName()
53+
exists(Property p, string qualifier, string name |
54+
c = TPropertyContent(p) and
55+
p.hasFullyQualifiedName(qualifier, name) and
56+
arg = getQualifiedName(qualifier, name) and
57+
result = "Property"
4958
)
5059
or
5160
exists(SyntheticField f |

csharp/ql/lib/semmle/code/csharp/security/dataflow/ExternalAPIsQuery.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ class ExternalApiUsedWithUntrustedData extends TExternalApi {
139139

140140
/** Gets a textual representation of this element. */
141141
string toString() {
142-
exists(Callable m, int index, string indexString |
142+
exists(Callable m, int index, string indexString, string qualifier, string name |
143143
if index = -1 then indexString = "qualifier" else indexString = "param " + index
144144
|
145145
this = TExternalApiParameter(m, index) and
146+
m.getDeclaringType().hasFullyQualifiedName(qualifier, name) and
146147
result =
147-
m.getDeclaringType().getFullyQualifiedName() + "." + m.toStringWithTypes() + " [" +
148-
indexString + "]"
148+
getQualifiedName(qualifier, name) + "." + m.toStringWithTypes() + " [" + indexString + "]"
149149
)
150150
}
151151
}

csharp/ql/test/library-tests/constructors/Destructors1.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ where
1010
c.getDeclaringType().hasFullyQualifiedName(qualifier, name) and
1111
qualifier = "Constructors" and
1212
name = "Class"
13-
select c, c.getDeclaringType().getFullyQualifiedName()
13+
select c, getQualifiedName(qualifier, name)

0 commit comments

Comments
 (0)