@@ -46,27 +46,35 @@ class Annotation extends @annotation, Expr {
46
46
47
47
/**
48
48
* Gets a value of an annotation element. This includes default values in case
49
- * no explicit value is specified.
49
+ * no explicit value is specified. For elements with an array value type this
50
+ * might have an `ArrayInit` as result. To properly handle array values, prefer
51
+ * the predicate `getAnArrayValue`.
50
52
*/
51
53
Expr getAValue ( ) { filteredAnnotValue ( this , _, result ) }
52
54
53
55
/**
54
56
* Gets the value of the annotation element with the specified `name`.
55
57
* This includes default values in case no explicit value is specified.
58
+ * For elements with an array value type this might have an `ArrayInit` as result.
59
+ * To properly handle array values, prefer the predicate `getAnArrayValue`.
56
60
*/
57
61
Expr getValue ( string name ) { filteredAnnotValue ( this , this .getAnnotationElement ( name ) , result ) }
58
62
59
63
/**
60
64
* If the value type of the annotation element with the specified `name` is an enum type,
61
65
* gets the enum constant used as value for that element. This includes default values in
62
66
* case no explicit value is specified.
67
+ *
68
+ * If the element value type is an enum type array, use `getAnEnumConstantArrayValue`.
63
69
*/
64
70
EnumConstant getEnumConstantValue ( string name ) { result = getValue ( name ) .( FieldRead ) .getField ( ) }
65
71
66
72
/**
67
73
* If the value type of the annotation element with the specified `name` is `String`,
68
74
* gets the string value used for that element. This includes default values in case no
69
75
* explicit value is specified.
76
+ *
77
+ * If the element value type is a string array, use `getAStringArrayValue`.
70
78
*/
71
79
string getStringValue ( string name ) {
72
80
// Uses CompileTimeConstantExpr instead of StringLiteral because value can
@@ -78,6 +86,8 @@ class Annotation extends @annotation, Expr {
78
86
* If the value type of the annotation element with the specified `name` is `int`,
79
87
* gets the int value used for that element. This includes default values in case no
80
88
* explicit value is specified.
89
+ *
90
+ * If the element value type is an `int` array, use `getAnIntArrayValue`.
81
91
*/
82
92
int getIntValue ( string name ) {
83
93
// Uses CompileTimeConstantExpr instead of IntegerLiteral because value can
@@ -100,6 +110,8 @@ class Annotation extends @annotation, Expr {
100
110
* If the annotation element with the specified `name` has a Java `Class` as value type,
101
111
* gets the referenced type used as value for that element. This includes default values
102
112
* in case no explicit value is specified.
113
+ *
114
+ * If the element value type is a `Class` array, use `getATypeArrayValue`.
103
115
*/
104
116
Type getTypeValue ( string name ) { result = getValue ( name ) .( TypeLiteral ) .getReferencedType ( ) }
105
117
@@ -125,6 +137,50 @@ class Annotation extends @annotation, Expr {
125
137
*/
126
138
deprecated Expr getAValue ( string name ) { result = getAnArrayValue ( name ) }
127
139
140
+ /**
141
+ * Gets a value of the annotation element with the specified `name`, which must be declared as an enum
142
+ * type array. This includes default values in case no explicit value is specified.
143
+ *
144
+ * If the annotation element is defined with an array initializer, then the result will be one of the
145
+ * elements of that array. Otherwise, the result will be the single expression defined for the value.
146
+ */
147
+ EnumConstant getAnEnumConstantArrayValue ( string name ) {
148
+ result = this .getAnArrayValue ( name ) .( FieldRead ) .getField ( )
149
+ }
150
+
151
+ /**
152
+ * Gets a value of the annotation element with the specified `name`, which must be declared as a string
153
+ * array. This includes default values in case no explicit value is specified.
154
+ *
155
+ * If the annotation element is defined with an array initializer, then the result will be one of the
156
+ * elements of that array. Otherwise, the result will be the single expression defined for the value.
157
+ */
158
+ string getAStringArrayValue ( string name ) {
159
+ result = this .getAnArrayValue ( name ) .( CompileTimeConstantExpr ) .getStringValue ( )
160
+ }
161
+
162
+ /**
163
+ * Gets a value of the annotation element with the specified `name`, which must be declared as an `int`
164
+ * array. This includes default values in case no explicit value is specified.
165
+ *
166
+ * If the annotation element is defined with an array initializer, then the result will be one of the
167
+ * elements of that array. Otherwise, the result will be the single expression defined for the value.
168
+ */
169
+ int getAnIntArrayValue ( string name ) {
170
+ result = this .getAnArrayValue ( name ) .( CompileTimeConstantExpr ) .getIntValue ( )
171
+ }
172
+
173
+ /**
174
+ * Gets a value of the annotation element with the specified `name`, which must be declared as a `Class`
175
+ * array. This includes default values in case no explicit value is specified.
176
+ *
177
+ * If the annotation element is defined with an array initializer, then the result will be one of the
178
+ * elements of that array. Otherwise, the result will be the single expression defined for the value.
179
+ */
180
+ Type getATypeArrayValue ( string name ) {
181
+ result = this .getAnArrayValue ( name ) .( TypeLiteral ) .getReferencedType ( )
182
+ }
183
+
128
184
/**
129
185
* Gets the value at a given index of the annotation element with the specified `name`, which must be
130
186
* declared as an array type. This includes default values in case no explicit value is specified.
0 commit comments