Bug 10587 - ast: missing node for a variable binding
Summary: ast: missing node for a variable binding
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.0 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-03-01 10:50 EST by Adam Kiezun CLA
Modified: 2002-03-01 14:08 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Kiezun CLA 2002-03-01 10:50:39 EST
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
Comment 1 Olivier Thomann CLA 2002-03-01 11:09:50 EST
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.
Comment 2 Adam Kiezun CLA 2002-03-01 11:15:51 EST
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.
Comment 3 Olivier Thomann CLA 2002-03-01 11:26:47 EST
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? 
Comment 4 Adam Kiezun CLA 2002-03-01 11:42:38 EST
afair(emember) i need it for locals only
Comment 5 Olivier Thomann CLA 2002-03-01 11:49:45 EST
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.
Comment 6 Olivier Thomann CLA 2002-03-01 14:08:43 EST
Fixed and released in HEAD. Regression tests added.