I am trying to visit method body with another treepathscanner, but I dont know, which parameter to pass, because I allways get a NPE in TreePath constructor.
@Override
public Object visitMethod(MethodTree node, Trees p) {
...
node.getBody().accept(new MethodVisitor(m, repository), node.getBody());
...
}
public class MethodVisitor extends TreePathScanner<Object, BlockTree> {...}
Exception:
An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.NullPointerException
at com.sun.source.util.TreePath.<init>(TreePath.java:94)
at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:65)
at com.sun.source.util.TreeScanner.scan(TreeScanner.java:90)
at com.sun.source.util.TreeScanner.visitBlock(TreeScanner.java:158)
at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:764)
at cz.cvut.kbss.odpa.parser.visitor.OdpaVisitor.visitMethod(OdpaVisitor.java:93)
at cz.cvut.kbss.odpa.parser.visitor.OdpaVisitor.visitMethod(OdpaVisitor.java:29)
at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:676)
at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:67)
...
Thanks for any help.
In case that someone needs it, the correct way to call it is:
new MethodVisitor(m, repository).scan(p.getPath(compilationUnitTree, node), node.getBody());