jeudi 19 septembre 2019

Get Class fields from annotated Object in annotation processor

i'm working on my first annotation processor. I'm trying to get fields of class through annotation on declared object(that is a field of a method). For example:

public class Person {
    private String name;
    private String surname;
}

...
public void myMethod(@MyAnnotation Person person) { 
    /*...*/
}
...

Through @MyAnnotation i want to get 'name' and 'surname' fields.

Is that possible? I did something of similar with method's field:

...
for (Element element : roundEnvironment.getElementsAnnotatedWith(AnnotationOnMethod.class)) {
    ExecutableElement method = (ExecutableElement) element;
    List<? extends VariableElement> parameters = method.getParameters();
    parameters.forEach(p -> {
        /*code here for parameter*/
    });
}
...


Thanks in advance, Luca.





Aucun commentaire:

Enregistrer un commentaire