2012-04-23 4 views
2

다른 treepathscanner를 사용하여 메서드 본문을 방문하려고합니다. 그러나 TreePath 생성자에서 NPE를 항상 가져 오기 때문에 전달할 매개 변수를 알지 못합니다.Java 컴파일러 트리 api : 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) 
    ... 

감사합니다. 경우

답변

2

누군가가 그것을 필요로하는, 호출하는 올바른 방법은 다음과 같습니다

new MethodVisitor(m, repository).scan(p.getPath(compilationUnitTree, node), node.getBody());