Java: Deprecate RefType.nestedName(), and add RefType.getNestedName()

This commit is contained in:
Ian Lynagh
2024-09-16 17:13:18 +01:00
parent e99d7db428
commit 41ed6e6695
13 changed files with 25 additions and 18 deletions

View File

@@ -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
)
}

View File

@@ -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.
*

View File

@@ -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) {