Skip to content

Commit 6beb396

Browse files
authored
Merge pull request #634 from yh-semmle/java/field-annotations
Java: account for change to field annotation extraction
2 parents a709783 + bc78219 commit 6beb396

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ class Annotation extends @annotation, Expr {
2424
predicate isTypeAnnotation() { this instanceof TypeAnnotation }
2525

2626
/** Gets the element being annotated. */
27-
Element getAnnotatedElement() { this.getParent() = result }
27+
Element getAnnotatedElement() {
28+
this.getParent().(Field).getDeclaration().getAField() = result and
29+
this.getCompilationUnit().fromSource()
30+
or
31+
not result.(Field).getCompilationUnit().fromSource() and
32+
this.getParent() = result
33+
}
2834

2935
/** Gets the annotation type declaration for this annotation. */
3036
override AnnotationType getType() { result = Expr.super.getType() }
@@ -41,7 +47,7 @@ class Annotation extends @annotation, Expr {
4147
Expr getValue(string name) { filteredAnnotValue(this, this.getAnnotationElement(name), result) }
4248

4349
/** Gets the element being annotated. */
44-
Element getTarget() { exprs(this, _, _, result, _) }
50+
Element getTarget() { result = getAnnotatedElement() }
4551

4652
override string toString() { result = this.getType().getName() }
4753

0 commit comments

Comments
 (0)