Java: Improve Annotation.getAnAssociatedAnnotation

As suggested by smowton during review.
This commit is contained in:
Marcono1234
2022-03-27 23:32:04 +02:00
committed by Chris Smowton
parent fd5fdd89d9
commit 47e38952d1

View File

@@ -217,13 +217,15 @@ class Annotatable extends Element {
) )
} }
private Annotation getAnAssociatedAnnotation(AnnotationType t) { private Annotation getADeclaredAssociatedAnnotation(AnnotationType t) {
result.getType() = t and
// Direct or indirect annotation // Direct or indirect annotation
if getADeclaredAnnotation().getType() = t or getAnIndirectAnnotation().getType() = t result.getType() = t and result = [getADeclaredAnnotation(), getAnIndirectAnnotation()]
then ( }
result = getADeclaredAnnotation() or result = getAnIndirectAnnotation()
) else ( private Annotation getAnAssociatedAnnotation(AnnotationType t) {
if exists(getADeclaredAssociatedAnnotation(t))
then result = getADeclaredAssociatedAnnotation(t)
else (
// Only if neither a direct nor an indirect annotation is present look for an inherited one // Only if neither a direct nor an indirect annotation is present look for an inherited one
t.isInherited() and t.isInherited() and
// @Inherited only works for classes; cast to Annotatable is necessary because predicate is private // @Inherited only works for classes; cast to Annotatable is necessary because predicate is private