Skip to content

Commit b96061a

Browse files
Marcono1234smowton
authored andcommitted
Java: Rename Annotation value predicates
1 parent c226758 commit b96061a

File tree

10 files changed

+19
-18
lines changed

10 files changed

+19
-18
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ class Annotation extends @annotation, Expr {
6161
* gets the enum constant used as value for that element. This includes default values in
6262
* case no explicit value is specified.
6363
*/
64-
EnumConstant getValueEnumConstant(string name) { result = getValue(name).(FieldRead).getField() }
64+
EnumConstant getEnumConstantValue(string name) { result = getValue(name).(FieldRead).getField() }
6565

6666
/**
6767
* If the value type of the annotation element with the specified `name` is `String`,
6868
* gets the string value used for that element. This includes default values in case no
6969
* explicit value is specified.
7070
*/
71-
string getValueString(string name) {
71+
string getStringValue(string name) {
7272
// Uses CompileTimeConstantExpr instead of StringLiteral because value can
7373
// be read of final variable as well
7474
result = getValue(name).(CompileTimeConstantExpr).getStringValue()
@@ -79,7 +79,7 @@ class Annotation extends @annotation, Expr {
7979
* gets the int value used for that element. This includes default values in case no
8080
* explicit value is specified.
8181
*/
82-
int getValueInt(string name) {
82+
int getIntValue(string name) {
8383
// Uses CompileTimeConstantExpr instead of IntegerLiteral because value can
8484
// be read of final variable as well
8585
result = getValue(name).(CompileTimeConstantExpr).getIntValue()
@@ -90,7 +90,7 @@ class Annotation extends @annotation, Expr {
9090
* gets the boolean value used for that element. This includes default values in case
9191
* no explicit value is specified.
9292
*/
93-
boolean getValueBoolean(string name) {
93+
boolean getBooleanValue(string name) {
9494
// Uses CompileTimeConstantExpr instead of BooleanLiteral because value can
9595
// be read of final variable as well
9696
result = getValue(name).(CompileTimeConstantExpr).getBooleanValue()
@@ -101,7 +101,7 @@ class Annotation extends @annotation, Expr {
101101
* gets the referenced type used as value for that element. This includes default values
102102
* in case no explicit value is specified.
103103
*/
104-
Type getValueClass(string name) { result = getValue(name).(TypeLiteral).getReferencedType() }
104+
Type getTypeValue(string name) { result = getValue(name).(TypeLiteral).getReferencedType() }
105105

106106
/** Gets the element being annotated. */
107107
Element getTarget() { result = this.getAnnotatedElement() }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class RepeatableAnnotation extends Annotation {
9999
* Gets the annotation type which acts as _containing type_, grouping multiple
100100
* repeatable annotations together.
101101
*/
102-
AnnotationType getContainingType() { result = getValueClass("value") }
102+
AnnotationType getContainingType() { result = getTypeValue("value") }
103103
}
104104

105105
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,13 @@ class TestNGTestMethod extends Method {
161161
exists(TestNGTestAnnotation testAnnotation |
162162
testAnnotation = this.getAnAnnotation() and
163163
// The data provider must have the same name as the referenced data provider
164-
result.getDataProviderName() = testAnnotation.getValueString("dataProvider")
164+
result.getDataProviderName() = testAnnotation.getStringValue("dataProvider")
165165
|
166166
// Either the data provider should be on the current class, or a supertype
167167
this.getDeclaringType().getAnAncestor() = result.getDeclaringType()
168168
or
169169
// Or the data provider class should be declared
170-
result.getDeclaringType() = testAnnotation.getValueClass("dataProviderClass")
170+
result.getDeclaringType() = testAnnotation.getTypeValue("dataProviderClass")
171171
)
172172
}
173173
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class JaxbType extends Class {
6060
this.getAnAnnotation() = a and
6161
a.getType().(JaxbAnnotationType).hasName("XmlAccessorType")
6262
|
63-
result = a.getValueEnumConstant("value")
63+
result = a.getEnumConstantValue("value")
6464
)
6565
}
6666

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ class RunWithAnnotation extends Annotation {
6464
/**
6565
* Gets the runner that will be used.
6666
*/
67-
Type getRunner() { result = this.getValueClass("value") }
67+
Type getRunner() { result = this.getTypeValue("value") }
6868
}

java/ql/lib/semmle/code/java/frameworks/javaee/Persistence.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ class PersistentEntity extends RefType {
3333
}
3434

3535
/**
36-
* Gets the access type for this entity as defined by a `@javax.persistence.Access` annotation, if any.
36+
* Gets the access type for this entity as defined by a `@javax.persistence.Access` annotation,
37+
* if any, in lower case.
3738
*/
3839
string getAccessTypeFromAnnotation() {
3940
exists(AccessAnnotation accessType | accessType = this.getAnAnnotation() |
40-
result = accessType.getValueEnumConstant("value").getName().toLowerCase()
41+
result = accessType.getEnumConstantValue("value").getName().toLowerCase()
4142
)
4243
}
4344
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ class SpringQualifierDefinitionAnnotation extends Annotation {
311311
/**
312312
* Gets the value of the qualifier field for this qualifier.
313313
*/
314-
string getQualifierValue() { result = this.getValueString("value") }
314+
string getQualifierValue() { result = this.getStringValue("value") }
315315
}
316316

317317
/**
@@ -323,7 +323,7 @@ class SpringQualifierAnnotation extends Annotation {
323323
/**
324324
* Gets the value of the qualifier field for this qualifier.
325325
*/
326-
string getQualifierValue() { result = getValueString("value") }
326+
string getQualifierValue() { result = getStringValue("value") }
327327

328328
/**
329329
* Gets the bean definition in an XML file that this qualifier resolves to, if any.
@@ -346,7 +346,7 @@ class SpringResourceAnnotation extends Annotation {
346346
/**
347347
* Gets the specified name value, if any.
348348
*/
349-
string getNameValue() { result = getValueString("name") }
349+
string getNameValue() { result = getStringValue("name") }
350350

351351
/**
352352
* Gets the bean definition in an XML file that the resource resolves to, if any.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class SpringComponent extends RefType {
144144
if exists(this.getComponentAnnotation().getValue("value"))
145145
then
146146
// If the name has been specified in the component annotation, use that.
147-
result = getComponentAnnotation().getValueString("value")
147+
result = getComponentAnnotation().getStringValue("value")
148148
else
149149
// Otherwise use the name of the class, with the initial letter lower cased.
150150
exists(string name | name = this.getName() |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class SpringRequestMappingMethod extends SpringControllerMethod {
155155

156156
/** Gets the "value" @RequestMapping annotation value, if present. */
157157
string getValue() {
158-
result = requestMappingAnnotation.getValueString("value")
158+
result = requestMappingAnnotation.getStringValue("value")
159159
}
160160

161161
/** Holds if this is considered an `@ResponseBody` method. */

java/ql/src/experimental/Security/CWE/CWE-352/JsonpInjectionLib.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class SpringControllerRequestMappingGetMethod extends SpringControllerGetMethod
4747
.getType()
4848
.hasQualifiedName("org.springframework.web.bind.annotation", "RequestMapping") and
4949
(
50-
this.getAnAnnotation().getValueEnumConstant("method").getName() = "GET" or
50+
this.getAnAnnotation().getEnumConstantValue("method").getName() = "GET" or
5151
this.getAnAnnotation().getValue("method").(ArrayInit).getSize() = 0 //Java code example: @RequestMapping(value = "test")
5252
) and
5353
not this.getAParamType().getName() = "MultipartFile"

0 commit comments

Comments
 (0)