I have a class that is annotated with my annotation and then I want to get all the class fields and then check if their methods contain a call to a specific service.
The issue is that the method body is always null in this case.
Just a small note the classes of the fields live in another module.
public boolean process( Set<? extends TypeElement> annotations, RoundEnvironment roundEnv )
{
Set<? extends Element> annotatedClasses = getAnnotatedClasses( annotations, roundEnv );
annotatedClasses.forEach(annotatedClass -> {
List<? extends Element> fields = getFields( annotatedClass );
fields.forEach( field -> {
List<ExecutableElement> methods = getMethods( field );
methods.forEach( method -> {
MethodScanner methodScanner = new MethodScanner();
MethodTree methodTree = methodScanner.scan( method, this.trees );
BlockTree body = methodTree.getBody();
}
}
}
}
The MethodScanner
class comes from here: Accessing source code from Java Annotation Processor
Any way of getting the method source code?
Thanks