views:

63

answers:

1

Is there a way to use jdt ASTParser to get the value of a String field declared in a java file. Actually what I need is to resolve any possible dependencies from other classes e.g.
public String str = "somethig"+SomeTherClass.SOMETHING_ELSE.

+1  A: 

I figured it out ...it was quite simple actually ..here's the code:

ICompilationUnit cu = ....
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setResolveBindings(true);
parser.setSource(cu);
parser.setStatementsRecovery(true);
parser.setBindingsRecovery(true);
ASTNode node = parser.createAST(null);
node.accept(new YourVisitor());

Then in your implementation of the ASTVisitor you need to call resolveConstantExpressionValue() on the node being visited.

Yasko