@@ -166,19 +166,33 @@ private predicate sourceAnnotValue(Annotation a, Method m, Expr val) {
166166
167167/** An abstract representation of language elements that can be annotated. */
168168class 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 ( ) ) }
171171
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+ */
173179 predicate hasAnnotation ( string package , string name ) {
174180 exists ( AnnotationType at | at = this .getAnAnnotation ( ) .getType ( ) |
175181 at .nestedName ( ) = name and at .getPackage ( ) .getName ( ) = package
176182 )
177183 }
178184
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
180189 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 }
182196
183197 /**
184198 * Holds if this or any enclosing `Annotatable` has a `@SuppressWarnings("<category>")`
0 commit comments