@@ -166,19 +166,33 @@ private predicate sourceAnnotValue(Annotation a, Method m, Expr val) {
166
166
167
167
/** An abstract representation of language elements that can be annotated. */
168
168
class Annotatable extends Element {
169
- /** Holds if this element has an annotation. */
170
- predicate hasAnnotation ( ) { exists ( Annotation a | a . getAnnotatedElement ( ) = this ) }
169
+ /** Holds if this element has an annotation, including inherited annotations . */
170
+ predicate hasAnnotation ( ) { exists ( getAnAnnotation ( ) ) }
171
171
172
- /** Holds if this element has the specified annotation. */
172
+ /** Holds if this element has a declared annotation, excluding inherited annotations. */
173
+ predicate hasDeclaredAnnotation ( ) { exists ( getADeclaredAnnotation ( ) ) }
174
+
175
+ /**
176
+ * Holds if this element has the specified annotation, including inherited
177
+ * annotations.
178
+ */
173
179
predicate hasAnnotation ( string package , string name ) {
174
180
exists ( AnnotationType at | at = this .getAnAnnotation ( ) .getType ( ) |
175
181
at .nestedName ( ) = name and at .getPackage ( ) .getName ( ) = package
176
182
)
177
183
}
178
184
179
- /** Gets an annotation that applies to this element. */
185
+ /**
186
+ * Gets an annotation that applies to this element, including inherited annotations.
187
+ */
188
+ // This predicate is overridden by Class to consider inherited annotations
180
189
cached
181
- Annotation getAnAnnotation ( ) { result .getAnnotatedElement ( ) = this }
190
+ Annotation getAnAnnotation ( ) { result = getADeclaredAnnotation ( ) }
191
+
192
+ /**
193
+ * Gets an annotation that is declared on this element, excluding inherited annotations.
194
+ */
195
+ Annotation getADeclaredAnnotation ( ) { result .getAnnotatedElement ( ) = this }
182
196
183
197
/**
184
198
* Holds if this or any enclosing `Annotatable` has a `@SuppressWarnings("<category>")`
0 commit comments