Skip to content

Commit b3b1efb

Browse files
authored
Merge pull request #10414 from igfoo/igfoo/getQualifiedName
Java: Tweak Member.getQualifiedName()
2 parents d713910 + 4ac0ecb commit b3b1efb

File tree

11 files changed

+129
-122
lines changed

11 files changed

+129
-122
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: breaking
3+
---
4+
* The `Member.getQualifiedName()` predicate result now includes the qualified name of the declaring type.

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ class Member extends Element, Annotatable, Modifiable, @member {
2020
/** Gets the type in which this member is declared. */
2121
RefType getDeclaringType() { declaresMember(result, this) }
2222

23-
/** Gets the qualified name of this member. */
24-
string getQualifiedName() { result = this.getDeclaringType().getName() + "." + this.getName() }
23+
/**
24+
* Gets the qualified name of this member.
25+
* This is useful for debugging, but for normal use `hasQualifiedName`
26+
* is recommended, as it is more efficient.
27+
*/
28+
string getQualifiedName() {
29+
result = this.getDeclaringType().getQualifiedName() + "." + this.getName()
30+
}
2531

2632
/**
2733
* Holds if this member has the specified name and is declared in the

java/ql/lib/semmle/code/java/security/ExternalAPIs.qll

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ private class DefaultSafeExternalApiMethod extends SafeExternalApiMethod {
2424
or
2525
this.getDeclaringType().hasQualifiedName("org.apache.commons.lang3", "Validate")
2626
or
27-
this.getQualifiedName() = "Objects.equals"
27+
this.hasQualifiedName("java.util", "Objects", "equals")
2828
or
2929
this.getDeclaringType() instanceof TypeString and this.getName() = "equals"
3030
or
@@ -92,10 +92,7 @@ class ExternalApiDataNode extends DataFlow::Node {
9292
int getIndex() { result = i }
9393

9494
/** Gets the description of the method being called. */
95-
string getMethodDescription() {
96-
result =
97-
this.getMethod().getDeclaringType().getPackage() + "." + this.getMethod().getQualifiedName()
98-
}
95+
string getMethodDescription() { result = this.getMethod().getQualifiedName() }
9996
}
10097

10198
/** DEPRECATED: Alias for ExternalApiDataNode */
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
| dc.kt:0:0:0:0 | hashCode(...) | Arrays.hashCode |
2-
| dc.kt:0:0:0:0 | hashCode(...) | Arrays.hashCode |
1+
| dc.kt:0:0:0:0 | hashCode(...) | java.util.Arrays.hashCode |
2+
| dc.kt:0:0:0:0 | hashCode(...) | java.util.Arrays.hashCode |
33
| dc.kt:0:0:0:0 | new ProtoMapValue(...) | ProtoMapValue.ProtoMapValue |
4-
| dc.kt:0:0:0:0 | plus(...) | Int.plus |
5-
| dc.kt:0:0:0:0 | times(...) | Int.times |
6-
| dc.kt:0:0:0:0 | toString(...) | Arrays.toString |
7-
| dc.kt:0:0:0:0 | toString(...) | Arrays.toString |
8-
| dc.kt:1:1:1:71 | super(...) | Object.Object |
4+
| dc.kt:0:0:0:0 | plus(...) | kotlin.Int.plus |
5+
| dc.kt:0:0:0:0 | times(...) | kotlin.Int.times |
6+
| dc.kt:0:0:0:0 | toString(...) | java.util.Arrays.toString |
7+
| dc.kt:0:0:0:0 | toString(...) | java.util.Arrays.toString |
8+
| dc.kt:1:1:1:71 | super(...) | java.lang.Object.Object |

java/ql/test/kotlin/library-tests/generics-location/locations.expected

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ classLocations
1212
| main.B<String> | file:///!unknown-binary-location/main/B.class:0:0:0:0 | file:///!unknown-binary-location/main/B.class:0:0:0:0 |
1313
| main.B<String> | generics-location.testproj/test.class.files/main/B.class:0:0:0:0 | generics-location.testproj/test.class.files/main/B.class:0:0:0:0 |
1414
callableLocations
15-
| A.fn | A.class:0:0:0:0 | A.class:0:0:0:0 |
16-
| A.fn | A.java:4:17:4:18 | A.java:4:17:4:18 |
17-
| A<Integer>.fn | A.class:0:0:0:0 | A.class:0:0:0:0 |
18-
| A<Object>.fn | file:///!unknown-binary-location/main/A.class:0:0:0:0 | file:///!unknown-binary-location/main/A.class:0:0:0:0 |
19-
| A<String>.fn | A.class:0:0:0:0 | A.class:0:0:0:0 |
20-
| A<String>.fn | file:///!unknown-binary-location/main/A.class:0:0:0:0 | file:///!unknown-binary-location/main/A.class:0:0:0:0 |
21-
| B.fn | generics-location.testproj/test.class.files/main/B.class:0:0:0:0 | generics-location.testproj/test.class.files/main/B.class:0:0:0:0 |
22-
| B.fn | generics.kt:4:5:10:5 | generics.kt:4:5:10:5 |
23-
| B<Integer>.fn | generics-location.testproj/test.class.files/main/B.class:0:0:0:0 | generics-location.testproj/test.class.files/main/B.class:0:0:0:0 |
24-
| B<Object>.fn | file:///!unknown-binary-location/main/B.class:0:0:0:0 | file:///!unknown-binary-location/main/B.class:0:0:0:0 |
25-
| B<String>.fn | file:///!unknown-binary-location/main/B.class:0:0:0:0 | file:///!unknown-binary-location/main/B.class:0:0:0:0 |
26-
| B<String>.fn | generics-location.testproj/test.class.files/main/B.class:0:0:0:0 | generics-location.testproj/test.class.files/main/B.class:0:0:0:0 |
15+
| main.A.fn | A.class:0:0:0:0 | A.class:0:0:0:0 |
16+
| main.A.fn | A.java:4:17:4:18 | A.java:4:17:4:18 |
17+
| main.A<Integer>.fn | A.class:0:0:0:0 | A.class:0:0:0:0 |
18+
| main.A<Object>.fn | file:///!unknown-binary-location/main/A.class:0:0:0:0 | file:///!unknown-binary-location/main/A.class:0:0:0:0 |
19+
| main.A<String>.fn | A.class:0:0:0:0 | A.class:0:0:0:0 |
20+
| main.A<String>.fn | file:///!unknown-binary-location/main/A.class:0:0:0:0 | file:///!unknown-binary-location/main/A.class:0:0:0:0 |
21+
| main.B.fn | generics-location.testproj/test.class.files/main/B.class:0:0:0:0 | generics-location.testproj/test.class.files/main/B.class:0:0:0:0 |
22+
| main.B.fn | generics.kt:4:5:10:5 | generics.kt:4:5:10:5 |
23+
| main.B<Integer>.fn | generics-location.testproj/test.class.files/main/B.class:0:0:0:0 | generics-location.testproj/test.class.files/main/B.class:0:0:0:0 |
24+
| main.B<Object>.fn | file:///!unknown-binary-location/main/B.class:0:0:0:0 | file:///!unknown-binary-location/main/B.class:0:0:0:0 |
25+
| main.B<String>.fn | file:///!unknown-binary-location/main/B.class:0:0:0:0 | file:///!unknown-binary-location/main/B.class:0:0:0:0 |
26+
| main.B<String>.fn | generics-location.testproj/test.class.files/main/B.class:0:0:0:0 | generics-location.testproj/test.class.files/main/B.class:0:0:0:0 |
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
| A.class:0:0:0:0 | foo | A<String>.foo | foo(java.lang.String) | A.java:4:10:4:12 | foo | A.foo |
2-
| A.java:4:10:4:12 | foo | A.foo | foo(java.lang.Object) | A.java:4:10:4:12 | foo | A.foo |
3-
| B.java:4:17:4:19 | foo | B.foo | foo(java.lang.String) | B.java:4:17:4:19 | foo | B.foo |
4-
| W.kt:4:5:4:17 | foo | A.foo | foo(java.lang.Object) | W.kt:4:5:4:17 | foo | A.foo |
5-
| W.kt:8:14:8:34 | foo | B.foo | foo(java.lang.String) | W.kt:8:14:8:34 | foo | B.foo |
6-
| file:///!unknown-binary-location/k/A.class:0:0:0:0 | foo | A<String>.foo | foo(java.lang.String) | W.kt:4:5:4:17 | foo | A.foo |
1+
| A.class:0:0:0:0 | foo | j.A<String>.foo | foo(java.lang.String) | A.java:4:10:4:12 | foo | j.A.foo |
2+
| A.java:4:10:4:12 | foo | j.A.foo | foo(java.lang.Object) | A.java:4:10:4:12 | foo | j.A.foo |
3+
| B.java:4:17:4:19 | foo | j.B.foo | foo(java.lang.String) | B.java:4:17:4:19 | foo | j.B.foo |
4+
| W.kt:4:5:4:17 | foo | k.A.foo | foo(java.lang.Object) | W.kt:4:5:4:17 | foo | k.A.foo |
5+
| W.kt:8:14:8:34 | foo | k.B.foo | foo(java.lang.String) | W.kt:8:14:8:34 | foo | k.B.foo |
6+
| file:///!unknown-binary-location/k/A.class:0:0:0:0 | foo | k.A<String>.foo | foo(java.lang.String) | W.kt:4:5:4:17 | foo | k.A.foo |
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
| file1.kt:4:18:4:23 | fun2(...) | file2.kt:3:5:3:18 | fun2 | Class2.fun2 | file2.kt:2:1:4:1 | Class2 |
22
| file1.kt:5:9:5:14 | fun3(...) | file3.kt:5:1:6:1 | fun3 | MyJvmName.fun3 | file3.kt:0:0:0:0 | MyJvmName |
33
| file1.kt:6:9:6:14 | fun4(...) | file4.kt:4:1:5:1 | fun4 | File4Kt.fun4 | file4.kt:0:0:0:0 | File4Kt |
4-
| file1.kt:11:29:11:56 | toArray(...) | file://<external>/CollectionToArray.class:0:0:0:0 | toArray | CollectionToArray.toArray | file://<external>/CollectionToArray.class:0:0:0:0 | CollectionToArray |
5-
| file1.kt:11:47:11:55 | listOf(...) | file://<external>/CollectionsKt.class:0:0:0:0 | listOf | CollectionsKt.listOf | file://<external>/CollectionsKt.class:0:0:0:0 | CollectionsKt |
4+
| file1.kt:11:29:11:56 | toArray(...) | file://<external>/CollectionToArray.class:0:0:0:0 | toArray | kotlin.jvm.internal.CollectionToArray.toArray | file://<external>/CollectionToArray.class:0:0:0:0 | CollectionToArray |
5+
| file1.kt:11:47:11:55 | listOf(...) | file://<external>/CollectionsKt.class:0:0:0:0 | listOf | kotlin.collections.CollectionsKt.listOf | file://<external>/CollectionsKt.class:0:0:0:0 | CollectionsKt |

0 commit comments

Comments
 (0)