Skip to content

Commit b677e89

Browse files
committed
C#: Deprecate getFullyQualifiedNameWithTypes.
1 parent 8fa9191 commit b677e89

File tree

8 files changed

+43
-13
lines changed

8 files changed

+43
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class Declaration extends NamedElement, @declaration {
8787
* }
8888
* ```
8989
*/
90-
string getFullyQualifiedNameWithTypes() {
90+
deprecated string getFullyQualifiedNameWithTypes() {
9191
exists(string fullqual, string qual, string name |
9292
this.getDeclaringType().hasFullyQualifiedName(qual, name) and
9393
fullqual = getQualifiedName(qual, name) and

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,28 @@ predicate splitQualifiedName(string qualifiedName, string qualifier, string name
219219
name = qualifiedName
220220
)
221221
}
222+
223+
/**
224+
* INTERNAL: Do not use.
225+
*
226+
* Gets the fully qualified name of this declaration, including types, for example
227+
* the fully qualified name with types of `M` on line 3 is `N.C.M(int, string)` in
228+
*
229+
* ```csharp
230+
* namespace N {
231+
* class C {
232+
* void M(int i, string s) { }
233+
* }
234+
* }
235+
* ```
236+
*/
237+
bindingset[d]
238+
string getFullyQualifiedNameWithTypes(Declaration d) {
239+
exists(string fullqual, string qual, string name |
240+
d.getDeclaringType().hasFullyQualifiedName(qual, name) and
241+
fullqual = getQualifiedName(qual, name) and
242+
if d instanceof NestedType
243+
then result = fullqual + "+" + d.toStringWithTypes()
244+
else result = fullqual + "." + d.toStringWithTypes()
245+
)
246+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import csharp
2+
import semmle.code.csharp.commons.QualifiedName
23
import semmle.code.csharp.dispatch.Dispatch
34

45
from DispatchCall call, Callable callable
56
where
67
callable = call.getADynamicTarget() and
78
callable.fromSource()
8-
select call, callable.getFullyQualifiedNameWithTypes()
9+
select call, getFullyQualifiedNameWithTypes(callable)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import csharp
2+
import semmle.code.csharp.commons.QualifiedName
23
import semmle.code.csharp.frameworks.System
34

45
from ValueOrRefType t, Method m, boolean b
56
where
67
t.fromSource() and
78
m = getInvokedDisposeMethod(t) and
89
if implementsDispose(t) then b = true else b = false
9-
select t, m.getFullyQualifiedNameWithTypes(), b
10+
select t, getFullyQualifiedNameWithTypes(m), b
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import csharp
2+
import semmle.code.csharp.commons.QualifiedName
23
import semmle.code.csharp.frameworks.System
34

45
from ValueOrRefType t, Method m, boolean b
56
where
67
t.fromSource() and
78
m = getInvokedEqualsMethod(t) and
89
if implementsEquals(t) then b = true else b = false
9-
select t, m.getFullyQualifiedNameWithTypes(), b
10+
select t, getFullyQualifiedNameWithTypes(m), b

csharp/ql/test/library-tests/generics/Generics.ql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,18 @@ query predicate test27(ConstructedType ct, UnboundGenericType ugt, UnboundGeneri
231231

232232
query predicate test28(UnboundGeneric ug, string s) {
233233
ug.fromSource() and
234-
s = ug.getFullyQualifiedNameWithTypes()
234+
s = getFullyQualifiedNameWithTypes(ug)
235235
}
236236

237237
query predicate test29(ConstructedGeneric cg, string s) {
238238
cg.fromSource() and
239-
s = cg.getFullyQualifiedNameWithTypes()
239+
s = getFullyQualifiedNameWithTypes(cg)
240240
}
241241

242242
query predicate test30(Declaration d, string s) {
243243
d.fromSource() and
244244
d instanceof @generic and
245-
s = d.getFullyQualifiedNameWithTypes() and
245+
s = getFullyQualifiedNameWithTypes(d) and
246246
d != d.getUnboundDeclaration() and
247247
not d instanceof Generic
248248
}
@@ -263,21 +263,21 @@ query predicate test33(ConstructedMethod cm, string s1, string s2) {
263263
exists(string namespace, string type, string name |
264264
cm.hasFullyQualifiedName(namespace, type, name) and s1 = getQualifiedName(namespace, type, name)
265265
) and
266-
cm.getFullyQualifiedNameWithTypes() = s2
266+
getFullyQualifiedNameWithTypes(cm) = s2
267267
}
268268

269269
query predicate test34(UnboundGeneric ug, string s1, string s2) {
270270
ug.fromSource() and
271271
exists(string qualifier, string name |
272272
ug.hasFullyQualifiedName(qualifier, name) and s1 = getQualifiedName(qualifier, name)
273273
) and
274-
ug.getFullyQualifiedNameWithTypes() = s2
274+
getFullyQualifiedNameWithTypes(ug) = s2
275275
}
276276

277277
query predicate test35(UnboundGenericMethod gm, string s1, string s2) {
278278
gm.fromSource() and
279279
exists(string namespace, string type, string name |
280280
gm.hasFullyQualifiedName(namespace, type, name) and s1 = getQualifiedName(namespace, type, name)
281281
) and
282-
gm.getFullyQualifiedNameWithTypes() = s2
282+
getFullyQualifiedNameWithTypes(gm) = s2
283283
}

csharp/ql/test/library-tests/overrides/Overrides22.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import csharp
2+
import semmle.code.csharp.commons.QualifiedName
23

34
from Overridable v1, Overridable v2, string kind
45
where
@@ -9,4 +10,4 @@ where
910
) and
1011
v1.fromSource() and
1112
v2.fromSource()
12-
select v1.getFullyQualifiedNameWithTypes(), v2.getFullyQualifiedNameWithTypes(), kind
13+
select getFullyQualifiedNameWithTypes(v1), getFullyQualifiedNameWithTypes(v2), kind

csharp/ql/test/library-tests/unification/Unification.ql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import semmle.code.csharp.commons.QualifiedName
12
import semmle.code.csharp.Unification
23

34
class InterestingType extends @type {
@@ -7,9 +8,9 @@ class InterestingType extends @type {
78
}
89

910
string toString() {
10-
result = this.(Type).getFullyQualifiedNameWithTypes()
11+
result = getFullyQualifiedNameWithTypes(this.(Type))
1112
or
12-
not exists(this.(Type).getFullyQualifiedNameWithTypes()) and
13+
not exists(getFullyQualifiedNameWithTypes(this.(Type))) and
1314
result = this.(Type).toStringWithTypes()
1415
}
1516

0 commit comments

Comments
 (0)