我正在尝试使用另一个树路径扫描仪访问方法主体,但我不知道要传递哪个参数,因为我总是在 TreePath 构造函数中获得 NPE。
@Override
public Object visitMethod(MethodTree node, Trees p) {
...
node.getBody().accept(new MethodVisitor(m, repository), node.getBody());
...
}
public class MethodVisitor extends TreePathScanner<Object, BlockTree> {...}
例外:
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)
...
感谢您的任何帮助。
如果有人需要它,正确的调用方法是:
new MethodVisitor(m, repository).scan(p.getPath(compilationUnitTree, node), node.getBody());