Skip to content

Commit fd5fdd8

Browse files
Marcono1234smowton
authored andcommitted
Java: Rename Annotation.getAValue predicates for array values
Predicate name could lead to confusion with non-array predicate getAValue()
1 parent b96061a commit fd5fdd8

File tree

6 files changed

+28
-19
lines changed

6 files changed

+28
-19
lines changed

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,25 @@ class Annotation extends @annotation, Expr {
115115
* Gets a value of the annotation element with the specified `name`, which must be declared as an array
116116
* type. This includes default values in case no explicit value is specified.
117117
*
118-
* If the annotation element is defined with an array initializer, then the returned value will
119-
* be one of the elements of that array. Otherwise, the returned value will be the single
120-
* expression defined for the value.
118+
* If the annotation element is defined with an array initializer, then the result will be one of the
119+
* elements of that array. Otherwise, the result will be the single expression defined for the value.
121120
*/
122-
Expr getAValue(string name) { result = getAValue(name, _) }
121+
Expr getAnArrayValue(string name) { result = getAnArrayValue(name, _) }
122+
123+
/**
124+
* DEPRECATED: Predicate has been renamed to `getAnArrayValue`
125+
*/
126+
deprecated Expr getAValue(string name) { result = getAnArrayValue(name) }
123127

124128
/**
125129
* Gets the value at a given index of the annotation element with the specified `name`, which must be
126130
* declared as an array type. This includes default values in case no explicit value is specified.
127131
*
128-
* If the annotation element is defined with an array initializer, then the returned value will
129-
* be the elements at the given index of that array. Otherwise, if the index is 0 the returned value
130-
* will be the single expression defined for the value.
132+
* If the annotation element is defined with an array initializer, then the result will be the element
133+
* at the given index of that array. Otherwise, the result will be the single expression defined for
134+
* the value and the `index` will be 0.
131135
*/
132-
Expr getAValue(string name, int index) {
136+
Expr getAnArrayValue(string name, int index) {
133137
this.getType().getAnnotationElement(name).getType() instanceof Array and
134138
exists(Expr value | value = this.getValue(name) |
135139
if value instanceof ArrayInit
@@ -140,6 +144,11 @@ class Annotation extends @annotation, Expr {
140144
)
141145
}
142146

147+
/**
148+
* DEPRECATED: Predicate has been renamed to `getAnArrayValue`
149+
*/
150+
deprecated Expr getAValue(string name, int index) { result = getAnArrayValue(name, index) }
151+
143152
override string getAPrimaryQlClass() { result = "Annotation" }
144153
}
145154

@@ -204,7 +213,7 @@ class Annotatable extends Element {
204213
containerAnn = getADeclaredAnnotation() and
205214
containerAnn.getType() = t.getContainingAnnotationType()
206215
|
207-
result = containerAnn.getAValue("value")
216+
result = containerAnn.getAnArrayValue("value")
208217
)
209218
}
210219

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ class SuppressWarningsAnnotation extends Annotation {
2323
* warning, prefer `getASuppressedWarning()`. That predicate considers more cases because it does not
2424
* restrict results to `StringLiteral`.
2525
*/
26-
StringLiteral getASuppressedWarningLiteral() { result = this.getAValue(_) }
26+
StringLiteral getASuppressedWarningLiteral() { result = this.getAnArrayValue("value") }
2727

2828
/** Gets the name of a warning suppressed by this annotation. */
2929
string getASuppressedWarning() {
3030
// Use CompileTimeConstantExpr because that covers more than StringLiteral result of getASuppressedWarningLiteral()
31-
result = this.getAValue(_).(CompileTimeConstantExpr).getStringValue()
31+
result = this.getAnArrayValue("value").(CompileTimeConstantExpr).getStringValue()
3232
}
3333
}
3434

@@ -44,7 +44,7 @@ class TargetAnnotation extends Annotation {
4444
*/
4545
Expr getATargetExpression() {
4646
not result instanceof ArrayInit and
47-
result = this.getAValue(_)
47+
result = this.getAnArrayValue("value")
4848
}
4949

5050
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class TestNGListenersAnnotation extends TestNGAnnotation {
226226
* Gets a listener defined in this annotation.
227227
*/
228228
TestNGListenerImpl getAListener() {
229-
result = this.getAValue("value").(TypeLiteral).getReferencedType()
229+
result = this.getAnArrayValue("value").(TypeLiteral).getReferencedType()
230230
}
231231
}
232232

java/ql/lib/semmle/code/java/frameworks/MyBatis.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class IbatisSqlOperationAnnotation extends Annotation {
8686
* Gets this annotation's SQL statement string.
8787
*/
8888
string getSqlValue() {
89-
result = this.getAValue("value").(CompileTimeConstantExpr).getStringValue()
89+
result = this.getAnArrayValue("value").(CompileTimeConstantExpr).getStringValue()
9090
}
9191
}
9292

java/ql/lib/semmle/code/java/frameworks/spring/SpringComponentScan.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ class SpringComponentScan extends Annotation {
4040
*/
4141
string getBasePackages() {
4242
// "value" and "basePackages" are synonymous, and are simple strings
43-
result = this.getAValue("basePackages").(StringLiteral).getValue()
43+
result = this.getAnArrayValue("basePackages").(StringLiteral).getValue()
4444
or
45-
result = this.getAValue("value").(StringLiteral).getValue()
45+
result = this.getAnArrayValue("value").(StringLiteral).getValue()
4646
or
4747
exists(TypeLiteral typeLiteral |
4848
// Base package classes are type literals whose package should be considered a base package.
49-
typeLiteral = this.getAValue("basePackageClasses")
49+
typeLiteral = this.getAnArrayValue("basePackageClasses")
5050
|
5151
result = typeLiteral.getReferencedType().(RefType).getPackage().getName()
5252
)
@@ -203,7 +203,7 @@ class SpringComponent extends RefType {
203203
.getType()
204204
.hasQualifiedName("org.springframework.context.annotation", "Profile")
205205
|
206-
result = profileAnnotation.getAValue("value").(StringLiteral).getValue()
206+
result = profileAnnotation.getAnArrayValue("value").(StringLiteral).getValue()
207207
)
208208
}
209209
}

java/ql/lib/semmle/code/java/frameworks/struts/StrutsAnnotations.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ class StrutsActionsAnnotation extends StrutsAnnotation {
3434
/**
3535
* Gets an Action annotation contained in this Actions annotation.
3636
*/
37-
StrutsActionAnnotation getAnAction() { result = this.getAValue("value") }
37+
StrutsActionAnnotation getAnAction() { result = this.getAnArrayValue("value") }
3838
}

0 commit comments

Comments
 (0)