Java: Clarify that Annotation value predicates have default value as result

This commit is contained in:
Marcono1234
2021-07-10 22:42:44 +02:00
committed by Chris Smowton
parent 536f5c7f89
commit afb7462052

View File

@@ -44,23 +44,29 @@ class Annotation extends @annotation, Expr {
result = this.getType().getAnnotationElement(name)
}
/** Gets a value of an annotation element. */
/**
* Gets a value of an annotation element. This includes default values in case
* no explicit value is specified.
*/
Expr getAValue() { filteredAnnotValue(this, _, result) }
/** Gets the value of the annotation element with the specified `name`. */
/**
* Gets the value of the annotation element with the specified `name`.
* This includes default values in case no explicit value is specified.
*/
Expr getValue(string name) { filteredAnnotValue(this, this.getAnnotationElement(name), result) }
/**
* If the value type of the annotation element with the specified `name` is an enum type,
* gets the enum constant used as value for that element.
* 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 getValueEnumConstant(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.
* gets the string value used for that element. This includes default values in case no
* explicit value is specified.
*/
string getValueString(string name) {
// Uses CompileTimeConstantExpr instead of StringLiteral because value can
@@ -70,7 +76,8 @@ class Annotation extends @annotation, Expr {
/**
* If the value type of the annotation element with the specified `name` is `int`,
* gets the int value used for that element.
* gets the int value used for that element. This includes default values in case no
* explicit value is specified.
*/
int getValueInt(string name) {
// Uses CompileTimeConstantExpr instead of IntegerLiteral because value can
@@ -80,7 +87,8 @@ class Annotation extends @annotation, Expr {
/**
* If the value type of the annotation element with the specified `name` is `boolean`,
* gets the boolean value used for that element.
* gets the boolean value used for that element. This includes default values in case
* no explicit value is specified.
*/
boolean getValueBoolean(string name) {
// Uses CompileTimeConstantExpr instead of BooleanLiteral because value can
@@ -90,7 +98,8 @@ class Annotation extends @annotation, Expr {
/**
* If the annotation element with the specified `name` has a Java `Class` as value type,
* gets the referenced type used as value for that element.
* 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() }
@@ -104,7 +113,7 @@ class Annotation extends @annotation, Expr {
/**
* Gets a value of the annotation element with the specified `name`, which must be declared as an array
* type.
* 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
@@ -114,7 +123,7 @@ class Annotation extends @annotation, Expr {
/**
* Gets the value at a given index of the annotation element with the specified `name`, which must be
* declared as an array type.
* 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