2

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.

1 Answer 1

2

In case that someone needs it, the correct way to call it is:

new MethodVisitor(m, repository).scan(p.getPath(compilationUnitTree, node), node.getBody());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.