我試圖用this article來試試eclipse jdt/ast。VariableDeclarationFragment節點resolveBindind()在eclipse/jdt/ast中返回null
這是java代碼作爲輸入:
class Hello
{
int hello()
{
int a = 0, b = 3;
/* hello */
{
b = a * 3;
}
return a;
}
public static void main(String[] args)
{
int z = 0, i = 3;
/* hello */
{
i = z * 3;
}
}
}
隨着ASTView,它表明已經VariableDeclarationFragment
相應的結合。
然而,在此VariableDeclarationFragment node
遊客代碼,我總是空值4個局部變量(A,B,Z,I)爲resolveBinding()
返回值。
這是怎麼回事?我使用日食靛藍。
這是代碼來獲取AST
private static CompilationUnit createCompilationUnit(String sourceFile) {
String source = readWithStringBuilder(sourceFile);
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(source.toCharArray()); // set source
parser.setResolveBindings(true); // we need bindings later on
return (CompilationUnit) parser.createAST(null /* IProgressMonitor */); // parse
}
我使用JDT/AST作爲一個獨立的Java程序,所以我不能給IJavaProject的訪問。感謝你的回答。 – prosseek