Skip to content

Commit 41ed6e6

Browse files
committed
Java: Deprecate RefType.nestedName(), and add RefType.getNestedName()
1 parent e99d7db commit 41ed6e6

File tree

13 files changed

+25
-18
lines changed

13 files changed

+25
-18
lines changed

java/ql/automodel/src/AutomodelAlertSinkUtil.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class PotentialSinkModelExpr extends Expr {
9999
) and
100100
(if argIdx = -1 then input = "Argument[this]" else input = "Argument[" + argIdx + "]") and
101101
package = callable.getDeclaringType().getPackage().getName() and
102-
type = callable.getDeclaringType().getErasure().(RefType).nestedName() and
102+
type = callable.getDeclaringType().getErasure().(RefType).getNestedName() and
103103
subtypes = considerSubtypes(callable) and
104104
name = callable.getName() and
105105
signature = ExternalFlow::paramsString(callable)

java/ql/automodel/src/AutomodelApplicationModeCharacteristics.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ class ApplicationModeMetadataExtractor extends string {
378378
package = callable.getDeclaringType().getPackage().getName() and
379379
// we're using the erased types because the MaD convention is to not specify type parameters.
380380
// Whether something is or isn't a sink doesn't usually depend on the type parameters.
381-
type = callable.getDeclaringType().getErasure().(RefType).nestedName() and
381+
type = callable.getDeclaringType().getErasure().(RefType).getNestedName() and
382382
subtypes = AutomodelJavaUtil::considerSubtypes(callable).toString() and
383383
name = callable.getName() and
384384
signature = ExternalFlow::paramsString(callable) and

java/ql/automodel/src/AutomodelFrameworkModeCharacteristics.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class FrameworkModeMetadataExtractor extends string {
319319
package = callable.getDeclaringType().getPackage().getName() and
320320
// we're using the erased types because the MaD convention is to not specify type parameters.
321321
// Whether something is or isn't a sink doesn't usually depend on the type parameters.
322-
type = callable.getDeclaringType().getErasure().(RefType).nestedName() and
322+
type = callable.getDeclaringType().getErasure().(RefType).getNestedName() and
323323
subtypes = AutomodelJavaUtil::considerSubtypes(callable).toString() and
324324
name = callable.getName() and
325325
signature = ExternalFlow::paramsString(callable) and
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: deprecated
3+
---
4+
* The `RefType.nestedName()` predicate has been deprecated, and `RefType.getNestedName()` added to replace it.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class Annotatable extends Element {
255255
*/
256256
predicate hasAnnotation(string package, string name) {
257257
exists(AnnotationType at | at = this.getAnAnnotation().getType() |
258-
at.nestedName() = name and at.getPackage().getName() = package
258+
at.getNestedName() = name and at.getPackage().getName() = package
259259
)
260260
}
261261

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ class RefType extends Type, Annotatable, Modifiable, @reftype {
592592
* to the name of the enclosing type, which might be a nested type as well.
593593
*/
594594
predicate hasQualifiedName(string package, string type) {
595-
this.getPackage().hasName(package) and type = this.nestedName()
595+
this.getPackage().hasName(package) and type = this.getNestedName()
596596
}
597597

598598
/**
@@ -601,7 +601,7 @@ class RefType extends Type, Annotatable, Modifiable, @reftype {
601601
override string getTypeDescriptor() {
602602
result =
603603
"L" + this.getPackage().getName().replaceAll(".", "/") + "/" +
604-
this.getSourceDeclaration().nestedName() + ";"
604+
this.getSourceDeclaration().getNestedName() + ";"
605605
}
606606

607607
/**
@@ -615,8 +615,8 @@ class RefType extends Type, Annotatable, Modifiable, @reftype {
615615
string getQualifiedName() {
616616
exists(string pkgName | pkgName = this.getPackage().getName() |
617617
if pkgName = ""
618-
then result = this.nestedName()
619-
else result = pkgName + "." + this.nestedName()
618+
then result = this.getNestedName()
619+
else result = pkgName + "." + this.getNestedName()
620620
)
621621
}
622622

@@ -627,12 +627,15 @@ class RefType extends Type, Annotatable, Modifiable, @reftype {
627627
* Otherwise the name of the nested type is prefixed with a `$` and appended to
628628
* the name of the enclosing type, which might be a nested type as well.
629629
*/
630-
string nestedName() {
630+
string getNestedName() {
631631
not this instanceof NestedType and result = this.getName()
632632
or
633-
this.(NestedType).getEnclosingType().nestedName() + "$" + this.getName() = result
633+
this.(NestedType).getEnclosingType().getNestedName() + "$" + this.getName() = result
634634
}
635635

636+
/** DEPRECATED: Alias for `getNestedName`. */
637+
deprecated string nestedName() { result = this.getNestedName() }
638+
636639
/**
637640
* Gets the source declaration of this type.
638641
*

java/ql/lib/semmle/code/java/dataflow/ExternalFlow.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,10 @@ private predicate elementSpec(
422422
private string getNestedName(Type t) {
423423
not t instanceof RefType and result = t.toString()
424424
or
425-
not t.(Array).getElementType() instanceof NestedType and result = t.(RefType).nestedName()
425+
not t.(Array).getElementType() instanceof NestedType and result = t.(RefType).getNestedName()
426426
or
427427
result =
428-
t.(Array).getElementType().(NestedType).getEnclosingType().nestedName() + "$" + t.getName()
428+
t.(Array).getElementType().(NestedType).getEnclosingType().getNestedName() + "$" + t.getName()
429429
}
430430

431431
private string getQualifiedName(Type t) {

java/ql/src/Security/CWE/CWE-295/InsecureTrustManager.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ from InsecureTrustManagerFlow::PathNode source, InsecureTrustManagerFlow::PathNo
1919
where InsecureTrustManagerFlow::flowPath(source, sink)
2020
select sink, source, sink, "This uses $@, which is defined in $@ and trusts any certificate.",
2121
source, "TrustManager",
22-
source.getNode().asExpr().(ClassInstanceExpr).getConstructedType() as type, type.nestedName()
22+
source.getNode().asExpr().(ClassInstanceExpr).getConstructedType() as type, type.getNestedName()

java/ql/src/Telemetry/ExternalApi.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ExternalApi extends Callable {
3030
string getApiName() {
3131
result =
3232
this.getDeclaringType().getPackage() + "." +
33-
this.getDeclaringType().getSourceDeclaration().nestedName() + "#" + this.getName() +
33+
this.getDeclaringType().getSourceDeclaration().getNestedName() + "#" + this.getName() +
3434
paramsString(this)
3535
}
3636

java/ql/src/utils/flowtestcasegenerator/FlowTestCaseUtils.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ string getShortNameIfPossible(Type t) {
101101
getRootSourceDeclaration(t) = any(TestCase tc).getADesiredImport() and
102102
exists(RefType replaced, string nestedName |
103103
replaced = replaceTypeVariable(t).getSourceDeclaration() and
104-
nestedName = replaced.nestedName().replaceAll("$", ".")
104+
nestedName = replaced.getNestedName().replaceAll("$", ".")
105105
|
106106
if isImportable(getRootSourceDeclaration(t))
107107
then result = nestedName

0 commit comments

Comments
 (0)