mirror of
https://github.com/github/codeql.git
synced 2026-02-20 08:53:49 +01:00
Java: Clarify that Annotatable predicates consider inherited annotations
Additionally changes `hasAnnotation()` to consider inherited annotations for consistency.
This commit is contained in:
committed by
Chris Smowton
parent
afb7462052
commit
f69b6eef7a
@@ -166,19 +166,33 @@ private predicate sourceAnnotValue(Annotation a, Method m, Expr val) {
|
||||
|
||||
/** An abstract representation of language elements that can be annotated. */
|
||||
class Annotatable extends Element {
|
||||
/** Holds if this element has an annotation. */
|
||||
predicate hasAnnotation() { exists(Annotation a | a.getAnnotatedElement() = this) }
|
||||
/** Holds if this element has an annotation, including inherited annotations. */
|
||||
predicate hasAnnotation() { exists(getAnAnnotation()) }
|
||||
|
||||
/** Holds if this element has the specified annotation. */
|
||||
/** Holds if this element has a declared annotation, excluding inherited annotations. */
|
||||
predicate hasDeclaredAnnotation() { exists(getADeclaredAnnotation()) }
|
||||
|
||||
/**
|
||||
* Holds if this element has the specified annotation, including inherited
|
||||
* annotations.
|
||||
*/
|
||||
predicate hasAnnotation(string package, string name) {
|
||||
exists(AnnotationType at | at = this.getAnAnnotation().getType() |
|
||||
at.nestedName() = name and at.getPackage().getName() = package
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets an annotation that applies to this element. */
|
||||
/**
|
||||
* Gets an annotation that applies to this element, including inherited annotations.
|
||||
*/
|
||||
// This predicate is overridden by Class to consider inherited annotations
|
||||
cached
|
||||
Annotation getAnAnnotation() { result.getAnnotatedElement() = this }
|
||||
Annotation getAnAnnotation() { result = getADeclaredAnnotation() }
|
||||
|
||||
/**
|
||||
* Gets an annotation that is declared on this element, excluding inherited annotations.
|
||||
*/
|
||||
Annotation getADeclaredAnnotation() { result.getAnnotatedElement() = this }
|
||||
|
||||
/**
|
||||
* Holds if this or any enclosing `Annotatable` has a `@SuppressWarnings("<category>")`
|
||||
|
||||
Reference in New Issue
Block a user