Community
Participate
Working Groups
package junit.framework; public class A { public int a() { int i= 0; return i; } } i call AST.parseCompilationUnit(fCu, true); to create CompilationUnit in a visitor, i have a pointer to the Name in the return statement i want to find the declaration this Name comes from. ok, i call name.resolveBinding() as expected, it's a VariableBinding next, i call cu.findDeclaringNode(binding); i get a null ! i looked in the binding <-> node maps in the AST (owner) - they're both empty
I have a problem. I connect the binding with its declaring node only when you asked for the binding resolution of the declaring node. In your example, as long as you don't ask for the binding of the local declaration 'i', I cannot return the proper declaring node for the resolved binding of the name 'i' in the return statement. I will try to see how to fix this.
fix would be nice because the whole point of me doing this dance is to find a temp declaration when you (in the editor) select a temp reference. so, i simply cannot ask for the binding of the declaration - because the declaration is what i'm trying to find.
The only solution I have right now is to resolve the binding of the declaration when I create the node. With this trick, the link between the declaration and its binding is always existing when you might refer to a name reference. The drawback is that it might slow down a little the creation of the tree. Do you need this feature for all declarations? I mean not just for the locals?
afair(emember) i need it for locals only
I can use a trick for locals, but the way the API is written, this findDeclaringNode can be used for any declarations. So I keep my code for now and I might reconsider it when I can discuss that point with Jim. He is not here today. With my actual code, your initial problem is fixed. I will release it later today.
Fixed and released in HEAD. Regression tests added.