vendredi 15 juillet 2016

How to access an annotation inside another one using AbstractProcessor -not reflection

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.

Aucun commentaire:

Enregistrer un commentaire