Given the following class hierarchy
public AClass {
String getSomething() { ... }
}
public BClass extends AClass {
@Override
@CustomAnnotation
String getSomething() { super.getSomething(); }
}
In a Gradle project with three sub-project as the following:
- A (where AClass is defined)
- B (where BClass is defined)
- processor (where the annotation processor is defined).
Project B has annotation processor dependency for project processor
I have an annotation processor to visit elements annotated with @CustomAnnoatition and I have a tree path scanner:
class MyScanner extends TreePathScanner<String, Trees> {
String result;
...
public String scan(TreePath treePath, Trees trees) {
super.scan(treePath, trees);
return result;
}
public String visitMethodInvocation(MethodInvocationTree node, Trees trees) {
// field result initialized here
return super.visitMethodInvocation(node, trees);
}
}
wehere TreePath is constructed from the ExecutableElement that represents my annotated method, i.e BClass.getSomething(), and Trees is instantiated from my proceessor's init method:
Trees.instance(processingEnv);.
As you can see the method body of BClass.getSomething() is just super.getSomething() and I would like to initiate an additional tree path scanning on that very method definition. Or with other words I would like to propagate the scanning to the super method element. How can I do that?
From visitMethodInvocation I have acquired the ExecutableElement for the super.getSomething()
and use it get a new TreePath for the scanning, but unfortunately for that element I got back a null from the getPath: trees.getPath(trees.getElement(this.getCurrentPath())) so this approach does not seem to be working.
Note from debugger I have seen that the enclosing TypeElements of the ExecutablElements, that is, AClass and BClass of AClass.getSomething() and BClass.getSomething() respectively, are treated somewhat differently as the latter has an explicit source file with an absolute path while the former has only some 'class source' without a real path.