Skip to content

Commit afb7462

Browse files
Marcono1234smowton
authored andcommitted
Java: Clarify that Annotation value predicates have default value as result
1 parent 536f5c7 commit afb7462

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,29 @@ class Annotation extends @annotation, Expr {
4444
result = this.getType().getAnnotationElement(name)
4545
}
4646

47-
/** Gets a value of an annotation element. */
47+
/**
48+
* Gets a value of an annotation element. This includes default values in case
49+
* no explicit value is specified.
50+
*/
4851
Expr getAValue() { filteredAnnotValue(this, _, result) }
4952

50-
/** Gets the value of the annotation element with the specified `name`. */
53+
/**
54+
* Gets the value of the annotation element with the specified `name`.
55+
* This includes default values in case no explicit value is specified.
56+
*/
5157
Expr getValue(string name) { filteredAnnotValue(this, this.getAnnotationElement(name), result) }
5258

5359
/**
5460
* If the value type of the annotation element with the specified `name` is an enum type,
55-
* gets the enum constant used as value for that element.
61+
* gets the enum constant used as value for that element. This includes default values in
62+
* case no explicit value is specified.
5663
*/
57-
EnumConstant getValueEnumConstant(string name) {
58-
result = getValue(name).(FieldRead).getField()
59-
}
64+
EnumConstant getValueEnumConstant(string name) { result = getValue(name).(FieldRead).getField() }
6065

6166
/**
6267
* If the value type of the annotation element with the specified `name` is `String`,
63-
* gets the string value used for that element.
68+
* gets the string value used for that element. This includes default values in case no
69+
* explicit value is specified.
6470
*/
6571
string getValueString(string name) {
6672
// Uses CompileTimeConstantExpr instead of StringLiteral because value can
@@ -70,7 +76,8 @@ class Annotation extends @annotation, Expr {
7076

7177
/**
7278
* If the value type of the annotation element with the specified `name` is `int`,
73-
* gets the int value used for that element.
79+
* gets the int value used for that element. This includes default values in case no
80+
* explicit value is specified.
7481
*/
7582
int getValueInt(string name) {
7683
// Uses CompileTimeConstantExpr instead of IntegerLiteral because value can
@@ -80,7 +87,8 @@ class Annotation extends @annotation, Expr {
8087

8188
/**
8289
* If the value type of the annotation element with the specified `name` is `boolean`,
83-
* gets the boolean value used for that element.
90+
* gets the boolean value used for that element. This includes default values in case
91+
* no explicit value is specified.
8492
*/
8593
boolean getValueBoolean(string name) {
8694
// Uses CompileTimeConstantExpr instead of BooleanLiteral because value can
@@ -90,7 +98,8 @@ class Annotation extends @annotation, Expr {
9098

9199
/**
92100
* If the annotation element with the specified `name` has a Java `Class` as value type,
93-
* gets the referenced type used as value for that element.
101+
* gets the referenced type used as value for that element. This includes default values
102+
* in case no explicit value is specified.
94103
*/
95104
Type getValueClass(string name) { result = getValue(name).(TypeLiteral).getReferencedType() }
96105

@@ -104,7 +113,7 @@ class Annotation extends @annotation, Expr {
104113

105114
/**
106115
* Gets a value of the annotation element with the specified `name`, which must be declared as an array
107-
* type.
116+
* type. This includes default values in case no explicit value is specified.
108117
*
109118
* If the annotation element is defined with an array initializer, then the returned value will
110119
* 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 {
114123

115124
/**
116125
* Gets the value at a given index of the annotation element with the specified `name`, which must be
117-
* declared as an array type.
126+
* declared as an array type. This includes default values in case no explicit value is specified.
118127
*
119128
* If the annotation element is defined with an array initializer, then the returned value will
120129
* be the elements at the given index of that array. Otherwise, if the index is 0 the returned value

0 commit comments

Comments
 (0)