mirror of
https://github.com/github/codeql.git
synced 2026-04-22 15:25:18 +02:00
Java: Deprecate RefType.nestedName(), and add RefType.getNestedName()
This commit is contained in:
@@ -99,7 +99,7 @@ class PotentialSinkModelExpr extends Expr {
|
||||
) and
|
||||
(if argIdx = -1 then input = "Argument[this]" else input = "Argument[" + argIdx + "]") and
|
||||
package = callable.getDeclaringType().getPackage().getName() and
|
||||
type = callable.getDeclaringType().getErasure().(RefType).nestedName() and
|
||||
type = callable.getDeclaringType().getErasure().(RefType).getNestedName() and
|
||||
subtypes = considerSubtypes(callable) and
|
||||
name = callable.getName() and
|
||||
signature = ExternalFlow::paramsString(callable)
|
||||
|
||||
@@ -378,7 +378,7 @@ class ApplicationModeMetadataExtractor extends string {
|
||||
package = callable.getDeclaringType().getPackage().getName() and
|
||||
// we're using the erased types because the MaD convention is to not specify type parameters.
|
||||
// Whether something is or isn't a sink doesn't usually depend on the type parameters.
|
||||
type = callable.getDeclaringType().getErasure().(RefType).nestedName() and
|
||||
type = callable.getDeclaringType().getErasure().(RefType).getNestedName() and
|
||||
subtypes = AutomodelJavaUtil::considerSubtypes(callable).toString() and
|
||||
name = callable.getName() and
|
||||
signature = ExternalFlow::paramsString(callable) and
|
||||
|
||||
@@ -319,7 +319,7 @@ class FrameworkModeMetadataExtractor extends string {
|
||||
package = callable.getDeclaringType().getPackage().getName() and
|
||||
// we're using the erased types because the MaD convention is to not specify type parameters.
|
||||
// Whether something is or isn't a sink doesn't usually depend on the type parameters.
|
||||
type = callable.getDeclaringType().getErasure().(RefType).nestedName() and
|
||||
type = callable.getDeclaringType().getErasure().(RefType).getNestedName() and
|
||||
subtypes = AutomodelJavaUtil::considerSubtypes(callable).toString() and
|
||||
name = callable.getName() and
|
||||
signature = ExternalFlow::paramsString(callable) and
|
||||
|
||||
4
java/ql/lib/change-notes/2024-09-16-nestedName.md
Normal file
4
java/ql/lib/change-notes/2024-09-16-nestedName.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: deprecated
|
||||
---
|
||||
* The `RefType.nestedName()` predicate has been deprecated, and `RefType.getNestedName()` added to replace it.
|
||||
@@ -255,7 +255,7 @@ class Annotatable extends Element {
|
||||
*/
|
||||
predicate hasAnnotation(string package, string name) {
|
||||
exists(AnnotationType at | at = this.getAnAnnotation().getType() |
|
||||
at.nestedName() = name and at.getPackage().getName() = package
|
||||
at.getNestedName() = name and at.getPackage().getName() = package
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -592,7 +592,7 @@ class RefType extends Type, Annotatable, Modifiable, @reftype {
|
||||
* to the name of the enclosing type, which might be a nested type as well.
|
||||
*/
|
||||
predicate hasQualifiedName(string package, string type) {
|
||||
this.getPackage().hasName(package) and type = this.nestedName()
|
||||
this.getPackage().hasName(package) and type = this.getNestedName()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -601,7 +601,7 @@ class RefType extends Type, Annotatable, Modifiable, @reftype {
|
||||
override string getTypeDescriptor() {
|
||||
result =
|
||||
"L" + this.getPackage().getName().replaceAll(".", "/") + "/" +
|
||||
this.getSourceDeclaration().nestedName() + ";"
|
||||
this.getSourceDeclaration().getNestedName() + ";"
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -615,8 +615,8 @@ class RefType extends Type, Annotatable, Modifiable, @reftype {
|
||||
string getQualifiedName() {
|
||||
exists(string pkgName | pkgName = this.getPackage().getName() |
|
||||
if pkgName = ""
|
||||
then result = this.nestedName()
|
||||
else result = pkgName + "." + this.nestedName()
|
||||
then result = this.getNestedName()
|
||||
else result = pkgName + "." + this.getNestedName()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -627,12 +627,15 @@ class RefType extends Type, Annotatable, Modifiable, @reftype {
|
||||
* Otherwise the name of the nested type is prefixed with a `$` and appended to
|
||||
* the name of the enclosing type, which might be a nested type as well.
|
||||
*/
|
||||
string nestedName() {
|
||||
string getNestedName() {
|
||||
not this instanceof NestedType and result = this.getName()
|
||||
or
|
||||
this.(NestedType).getEnclosingType().nestedName() + "$" + this.getName() = result
|
||||
this.(NestedType).getEnclosingType().getNestedName() + "$" + this.getName() = result
|
||||
}
|
||||
|
||||
/** DEPRECATED: Alias for `getNestedName`. */
|
||||
deprecated string nestedName() { result = this.getNestedName() }
|
||||
|
||||
/**
|
||||
* Gets the source declaration of this type.
|
||||
*
|
||||
|
||||
@@ -422,10 +422,10 @@ private predicate elementSpec(
|
||||
private string getNestedName(Type t) {
|
||||
not t instanceof RefType and result = t.toString()
|
||||
or
|
||||
not t.(Array).getElementType() instanceof NestedType and result = t.(RefType).nestedName()
|
||||
not t.(Array).getElementType() instanceof NestedType and result = t.(RefType).getNestedName()
|
||||
or
|
||||
result =
|
||||
t.(Array).getElementType().(NestedType).getEnclosingType().nestedName() + "$" + t.getName()
|
||||
t.(Array).getElementType().(NestedType).getEnclosingType().getNestedName() + "$" + t.getName()
|
||||
}
|
||||
|
||||
private string getQualifiedName(Type t) {
|
||||
|
||||
@@ -19,4 +19,4 @@ from InsecureTrustManagerFlow::PathNode source, InsecureTrustManagerFlow::PathNo
|
||||
where InsecureTrustManagerFlow::flowPath(source, sink)
|
||||
select sink, source, sink, "This uses $@, which is defined in $@ and trusts any certificate.",
|
||||
source, "TrustManager",
|
||||
source.getNode().asExpr().(ClassInstanceExpr).getConstructedType() as type, type.nestedName()
|
||||
source.getNode().asExpr().(ClassInstanceExpr).getConstructedType() as type, type.getNestedName()
|
||||
|
||||
@@ -30,7 +30,7 @@ class ExternalApi extends Callable {
|
||||
string getApiName() {
|
||||
result =
|
||||
this.getDeclaringType().getPackage() + "." +
|
||||
this.getDeclaringType().getSourceDeclaration().nestedName() + "#" + this.getName() +
|
||||
this.getDeclaringType().getSourceDeclaration().getNestedName() + "#" + this.getName() +
|
||||
paramsString(this)
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ string getShortNameIfPossible(Type t) {
|
||||
getRootSourceDeclaration(t) = any(TestCase tc).getADesiredImport() and
|
||||
exists(RefType replaced, string nestedName |
|
||||
replaced = replaceTypeVariable(t).getSourceDeclaration() and
|
||||
nestedName = replaced.nestedName().replaceAll("$", ".")
|
||||
nestedName = replaced.getNestedName().replaceAll("$", ".")
|
||||
|
|
||||
if isImportable(getRootSourceDeclaration(t))
|
||||
then result = nestedName
|
||||
|
||||
@@ -27,7 +27,7 @@ class Endpoint extends Callable {
|
||||
/**
|
||||
* Gets the type name of this endpoint.
|
||||
*/
|
||||
string getTypeName() { result = this.getDeclaringType().nestedName() }
|
||||
string getTypeName() { result = this.getDeclaringType().getNestedName() }
|
||||
|
||||
/**
|
||||
* Gets the parameter types of this endpoint.
|
||||
|
||||
@@ -154,7 +154,7 @@ private string isExtensible(Callable c) {
|
||||
private predicate qualifiedName(Callable c, string package, string type) {
|
||||
exists(RefType t | t = c.getDeclaringType() |
|
||||
package = t.getCompilationUnit().getPackage().getName() and
|
||||
type = t.getErasure().(J::RefType).nestedName()
|
||||
type = t.getErasure().(J::RefType).getNestedName()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ module NeutralSinkTest implements TestSig {
|
||||
exists(Call call, Callable callable |
|
||||
call.getCallee() = callable and
|
||||
neutralModel(callable.getDeclaringType().getCompilationUnit().getPackage().getName(),
|
||||
callable.getDeclaringType().getSourceDeclaration().nestedName(), callable.getName(),
|
||||
callable.getDeclaringType().getSourceDeclaration().getNestedName(), callable.getName(),
|
||||
[paramsString(callable), ""], "sink", _) and
|
||||
call.getLocation() = location and
|
||||
element = call.toString() and
|
||||
|
||||
Reference in New Issue
Block a user