Java: Rename Annotation.getAValue predicates for array values

Predicate name could lead to confusion with non-array predicate getAValue()
This commit is contained in:
Marcono1234
2022-03-27 23:25:48 +02:00
committed by Chris Smowton
parent b96061aa7e
commit fd5fdd89d9
6 changed files with 28 additions and 19 deletions

View File

@@ -115,21 +115,25 @@ class Annotation extends @annotation, Expr {
* Gets a value of the annotation element with the specified `name`, which must be declared as an array
* type. This includes default values in case no explicit value is specified.
*
* If the annotation element is defined with an array initializer, then the returned value will
* be one of the elements of that array. Otherwise, the returned value will be the single
* expression defined for the value.
* If the annotation element is defined with an array initializer, then the result will be one of the
* elements of that array. Otherwise, the result will be the single expression defined for the value.
*/
Expr getAValue(string name) { result = getAValue(name, _) }
Expr getAnArrayValue(string name) { result = getAnArrayValue(name, _) }
/**
* DEPRECATED: Predicate has been renamed to `getAnArrayValue`
*/
deprecated Expr getAValue(string name) { result = getAnArrayValue(name) }
/**
* Gets the value at a given index of the annotation element with the specified `name`, which must be
* declared as an array type. This includes default values in case no explicit value is specified.
*
* If the annotation element is defined with an array initializer, then the returned value will
* be the elements at the given index of that array. Otherwise, if the index is 0 the returned value
* will be the single expression defined for the value.
* If the annotation element is defined with an array initializer, then the result will be the element
* at the given index of that array. Otherwise, the result will be the single expression defined for
* the value and the `index` will be 0.
*/
Expr getAValue(string name, int index) {
Expr getAnArrayValue(string name, int index) {
this.getType().getAnnotationElement(name).getType() instanceof Array and
exists(Expr value | value = this.getValue(name) |
if value instanceof ArrayInit
@@ -140,6 +144,11 @@ class Annotation extends @annotation, Expr {
)
}
/**
* DEPRECATED: Predicate has been renamed to `getAnArrayValue`
*/
deprecated Expr getAValue(string name, int index) { result = getAnArrayValue(name, index) }
override string getAPrimaryQlClass() { result = "Annotation" }
}
@@ -204,7 +213,7 @@ class Annotatable extends Element {
containerAnn = getADeclaredAnnotation() and
containerAnn.getType() = t.getContainingAnnotationType()
|
result = containerAnn.getAValue("value")
result = containerAnn.getAnArrayValue("value")
)
}

View File

@@ -23,12 +23,12 @@ class SuppressWarningsAnnotation extends Annotation {
* warning, prefer `getASuppressedWarning()`. That predicate considers more cases because it does not
* restrict results to `StringLiteral`.
*/
StringLiteral getASuppressedWarningLiteral() { result = this.getAValue(_) }
StringLiteral getASuppressedWarningLiteral() { result = this.getAnArrayValue("value") }
/** Gets the name of a warning suppressed by this annotation. */
string getASuppressedWarning() {
// Use CompileTimeConstantExpr because that covers more than StringLiteral result of getASuppressedWarningLiteral()
result = this.getAValue(_).(CompileTimeConstantExpr).getStringValue()
result = this.getAnArrayValue("value").(CompileTimeConstantExpr).getStringValue()
}
}
@@ -44,7 +44,7 @@ class TargetAnnotation extends Annotation {
*/
Expr getATargetExpression() {
not result instanceof ArrayInit and
result = this.getAValue(_)
result = this.getAnArrayValue("value")
}
/**

View File

@@ -226,7 +226,7 @@ class TestNGListenersAnnotation extends TestNGAnnotation {
* Gets a listener defined in this annotation.
*/
TestNGListenerImpl getAListener() {
result = this.getAValue("value").(TypeLiteral).getReferencedType()
result = this.getAnArrayValue("value").(TypeLiteral).getReferencedType()
}
}

View File

@@ -86,7 +86,7 @@ class IbatisSqlOperationAnnotation extends Annotation {
* Gets this annotation's SQL statement string.
*/
string getSqlValue() {
result = this.getAValue("value").(CompileTimeConstantExpr).getStringValue()
result = this.getAnArrayValue("value").(CompileTimeConstantExpr).getStringValue()
}
}

View File

@@ -40,13 +40,13 @@ class SpringComponentScan extends Annotation {
*/
string getBasePackages() {
// "value" and "basePackages" are synonymous, and are simple strings
result = this.getAValue("basePackages").(StringLiteral).getValue()
result = this.getAnArrayValue("basePackages").(StringLiteral).getValue()
or
result = this.getAValue("value").(StringLiteral).getValue()
result = this.getAnArrayValue("value").(StringLiteral).getValue()
or
exists(TypeLiteral typeLiteral |
// Base package classes are type literals whose package should be considered a base package.
typeLiteral = this.getAValue("basePackageClasses")
typeLiteral = this.getAnArrayValue("basePackageClasses")
|
result = typeLiteral.getReferencedType().(RefType).getPackage().getName()
)
@@ -203,7 +203,7 @@ class SpringComponent extends RefType {
.getType()
.hasQualifiedName("org.springframework.context.annotation", "Profile")
|
result = profileAnnotation.getAValue("value").(StringLiteral).getValue()
result = profileAnnotation.getAnArrayValue("value").(StringLiteral).getValue()
)
}
}

View File

@@ -34,5 +34,5 @@ class StrutsActionsAnnotation extends StrutsAnnotation {
/**
* Gets an Action annotation contained in this Actions annotation.
*/
StrutsActionAnnotation getAnAction() { result = this.getAValue("value") }
StrutsActionAnnotation getAnAction() { result = this.getAnArrayValue("value") }
}