I'm trying to try out eclipse jdt/ast following this article.
This is the java code as an input:
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;
}
}
}
With ASTView, it shows that VariableDeclarationFragment
has corresponding binding.
However, in this visitor code for VariableDeclarationFragment node
, I always get null value for 4 local variables (a,b,z,i) as resolveBinding()
return value.
What's wrong with this? I use eclipse indigo.
This is the code to get the 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
}