SaiNageswar S
SaiNageswar S

Reputation: 1336

Find undeclared variables in MethodDeclaration Eclipse JDT

How can we find undeclared variables in eclipse's JDT MethodDeclaration body?

Upvotes: 0

Views: 83

Answers (1)

Stephan Herrmann
Stephan Herrmann

Reputation: 8178

I assume you are looking for references that cannot be resolved (because the intended variable has not been declared), right?

You should create your AST with setResolveBindings(true) and then search for Names whose resolveBinding() is null. This will also find unresolved type references, where a SimpleType or QualifiedType contains a Name node. This can be detected by asking name.getParent() instanceof Type. If true then it's not a variable reference.

Upvotes: 1

Related Questions