mirror of
https://github.com/github/codeql.git
synced 2025-12-23 12:16:33 +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>")`
|
||||
|
||||
@@ -120,7 +120,7 @@ private newtype TPrintAstNode =
|
||||
shouldPrint(lvde, _) and lvde.getParent() instanceof SingleLocalVarDeclParent
|
||||
} or
|
||||
TAnnotationsNode(Annotatable ann) {
|
||||
shouldPrint(ann, _) and ann.hasAnnotation() and not partOfAnnotation(ann)
|
||||
shouldPrint(ann, _) and ann.hasDeclaredAnnotation() and not partOfAnnotation(ann)
|
||||
} or
|
||||
TParametersNode(Callable c) { shouldPrint(c, _) and not c.hasNoParameters() } or
|
||||
TBaseTypesNode(ClassOrInterface ty) { shouldPrint(ty, _) } or
|
||||
|
||||
Reference in New Issue
Block a user