Skip to content

Commit 47e3895

Browse files
Marcono1234smowton
authored andcommitted
Java: Improve Annotation.getAnAssociatedAnnotation
As suggested by smowton during review.
1 parent fd5fdd8 commit 47e3895

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

java/ql/lib/semmle/code/java/Annotation.qll

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,15 @@ class Annotatable extends Element {
217217
)
218218
}
219219

220-
private Annotation getAnAssociatedAnnotation(AnnotationType t) {
221-
result.getType() = t and
220+
private Annotation getADeclaredAssociatedAnnotation(AnnotationType t) {
222221
// Direct or indirect annotation
223-
if getADeclaredAnnotation().getType() = t or getAnIndirectAnnotation().getType() = t
224-
then (
225-
result = getADeclaredAnnotation() or result = getAnIndirectAnnotation()
226-
) else (
222+
result.getType() = t and result = [getADeclaredAnnotation(), getAnIndirectAnnotation()]
223+
}
224+
225+
private Annotation getAnAssociatedAnnotation(AnnotationType t) {
226+
if exists(getADeclaredAssociatedAnnotation(t))
227+
then result = getADeclaredAssociatedAnnotation(t)
228+
else (
227229
// Only if neither a direct nor an indirect annotation is present look for an inherited one
228230
t.isInherited() and
229231
// @Inherited only works for classes; cast to Annotatable is necessary because predicate is private

0 commit comments

Comments
 (0)