Given these types:
@Retention(RUNTIME)
@Target(ANNOTATION_TYPE)
public @interface Annotation1 {
}
@Retention(RUNTIME)
@Target(TYPE)
@Annotation1
public @interface Annotation2 {
}
@Annotation2
public class Mock {
}
I'm able to access the Annotation2 from Mock class using an AbstractProcessor, as follows:
Element element = //obtained from RoundEnvironment instance.
AnnotationMirror annotationMirror = element.getAnnotationMirrors().get(0);
But when I query for the annotations annotated in the pevious annotationMirror- which is a mirror of Annotation2, I got an empty list.
annotationMirror
.getAnnotationType()
.asElement()
.getAnnotationMirrors();
I think somehow this question is related to this one.
The code posted in the question works fine.
annotationMirror
.getAnnotationType()
.asElement()
.getAnnotationMirrors();
The problem was related with a missing import in the source code used for testing purpose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With