Java: Rename Annotation value predicates

This commit is contained in:
Marcono1234
2022-03-27 23:09:35 +02:00
committed by Chris Smowton
parent c226758889
commit b96061aa7e
10 changed files with 19 additions and 18 deletions

View File

@@ -61,14 +61,14 @@ class Annotation extends @annotation, Expr {
* gets the enum constant used as value for that element. This includes default values in
* case no explicit value is specified.
*/
EnumConstant getValueEnumConstant(string name) { result = getValue(name).(FieldRead).getField() }
EnumConstant getEnumConstantValue(string name) { result = getValue(name).(FieldRead).getField() }
/**
* If the value type of the annotation element with the specified `name` is `String`,
* gets the string value used for that element. This includes default values in case no
* explicit value is specified.
*/
string getValueString(string name) {
string getStringValue(string name) {
// Uses CompileTimeConstantExpr instead of StringLiteral because value can
// be read of final variable as well
result = getValue(name).(CompileTimeConstantExpr).getStringValue()
@@ -79,7 +79,7 @@ class Annotation extends @annotation, Expr {
* gets the int value used for that element. This includes default values in case no
* explicit value is specified.
*/
int getValueInt(string name) {
int getIntValue(string name) {
// Uses CompileTimeConstantExpr instead of IntegerLiteral because value can
// be read of final variable as well
result = getValue(name).(CompileTimeConstantExpr).getIntValue()
@@ -90,7 +90,7 @@ class Annotation extends @annotation, Expr {
* gets the boolean value used for that element. This includes default values in case
* no explicit value is specified.
*/
boolean getValueBoolean(string name) {
boolean getBooleanValue(string name) {
// Uses CompileTimeConstantExpr instead of BooleanLiteral because value can
// be read of final variable as well
result = getValue(name).(CompileTimeConstantExpr).getBooleanValue()
@@ -101,7 +101,7 @@ class Annotation extends @annotation, Expr {
* gets the referenced type used as value for that element. This includes default values
* in case no explicit value is specified.
*/
Type getValueClass(string name) { result = getValue(name).(TypeLiteral).getReferencedType() }
Type getTypeValue(string name) { result = getValue(name).(TypeLiteral).getReferencedType() }
/** Gets the element being annotated. */
Element getTarget() { result = this.getAnnotatedElement() }

View File

@@ -99,7 +99,7 @@ class RepeatableAnnotation extends Annotation {
* Gets the annotation type which acts as _containing type_, grouping multiple
* repeatable annotations together.
*/
AnnotationType getContainingType() { result = getValueClass("value") }
AnnotationType getContainingType() { result = getTypeValue("value") }
}
/**

View File

@@ -161,13 +161,13 @@ class TestNGTestMethod extends Method {
exists(TestNGTestAnnotation testAnnotation |
testAnnotation = this.getAnAnnotation() and
// The data provider must have the same name as the referenced data provider
result.getDataProviderName() = testAnnotation.getValueString("dataProvider")
result.getDataProviderName() = testAnnotation.getStringValue("dataProvider")
|
// Either the data provider should be on the current class, or a supertype
this.getDeclaringType().getAnAncestor() = result.getDeclaringType()
or
// Or the data provider class should be declared
result.getDeclaringType() = testAnnotation.getValueClass("dataProviderClass")
result.getDeclaringType() = testAnnotation.getTypeValue("dataProviderClass")
)
}
}

View File

@@ -60,7 +60,7 @@ class JaxbType extends Class {
this.getAnAnnotation() = a and
a.getType().(JaxbAnnotationType).hasName("XmlAccessorType")
|
result = a.getValueEnumConstant("value")
result = a.getEnumConstantValue("value")
)
}

View File

@@ -64,5 +64,5 @@ class RunWithAnnotation extends Annotation {
/**
* Gets the runner that will be used.
*/
Type getRunner() { result = this.getValueClass("value") }
Type getRunner() { result = this.getTypeValue("value") }
}

View File

@@ -33,11 +33,12 @@ class PersistentEntity extends RefType {
}
/**
* Gets the access type for this entity as defined by a `@javax.persistence.Access` annotation, if any.
* Gets the access type for this entity as defined by a `@javax.persistence.Access` annotation,
* if any, in lower case.
*/
string getAccessTypeFromAnnotation() {
exists(AccessAnnotation accessType | accessType = this.getAnAnnotation() |
result = accessType.getValueEnumConstant("value").getName().toLowerCase()
result = accessType.getEnumConstantValue("value").getName().toLowerCase()
)
}
}

View File

@@ -311,7 +311,7 @@ class SpringQualifierDefinitionAnnotation extends Annotation {
/**
* Gets the value of the qualifier field for this qualifier.
*/
string getQualifierValue() { result = this.getValueString("value") }
string getQualifierValue() { result = this.getStringValue("value") }
}
/**
@@ -323,7 +323,7 @@ class SpringQualifierAnnotation extends Annotation {
/**
* Gets the value of the qualifier field for this qualifier.
*/
string getQualifierValue() { result = getValueString("value") }
string getQualifierValue() { result = getStringValue("value") }
/**
* Gets the bean definition in an XML file that this qualifier resolves to, if any.
@@ -346,7 +346,7 @@ class SpringResourceAnnotation extends Annotation {
/**
* Gets the specified name value, if any.
*/
string getNameValue() { result = getValueString("name") }
string getNameValue() { result = getStringValue("name") }
/**
* Gets the bean definition in an XML file that the resource resolves to, if any.

View File

@@ -144,7 +144,7 @@ class SpringComponent extends RefType {
if exists(this.getComponentAnnotation().getValue("value"))
then
// If the name has been specified in the component annotation, use that.
result = getComponentAnnotation().getValueString("value")
result = getComponentAnnotation().getStringValue("value")
else
// Otherwise use the name of the class, with the initial letter lower cased.
exists(string name | name = this.getName() |

View File

@@ -155,7 +155,7 @@ class SpringRequestMappingMethod extends SpringControllerMethod {
/** Gets the "value" @RequestMapping annotation value, if present. */
string getValue() {
result = requestMappingAnnotation.getValueString("value")
result = requestMappingAnnotation.getStringValue("value")
}
/** Holds if this is considered an `@ResponseBody` method. */