Community
Participate
Working Groups
Build 20020129 package object_in; public class TestNestedRead { public TestNestedRead field; public int i; public int foo() { return field.field.field.field.i; } } For the QualifiedName node field.field...i the start position of the simple names is always -1 and the length is always 0. Furthermore the class resolveBinding on the SimpleName node always returns null.
The qualified name which contains field.field.field.field.i has source positions, but what you want is intermediate source positions for simple names in the qualified name?
I fixed the positions problem for all sub parts of the qualified name. Unfortunately I don't see how it could be possible to get the intermediate bindings. The problem is that I only get one qualified reference for all the nodes I create. Then I can only point the enclosing qualified name to the corresponding binding. Is this a problem for you? Let me know if the latest version works as expected.
Now resolveBinding() on the simpleName 'i' gives the VariableBinding corresponding to the field declaration 'i' in the class TestNestedRead. resolveTypeBinding() returns the ITypeBinding corresponding to the primitive type int. It is not possible to get the resolveTypeBinding() or resolveBinding() on the sub parts field.field.field.field, field.field.field ,field.field and field. I have the resolved binding, but I have only one qualified name reference for all the sub parts. You can ask resolveTypeBinding() on field.field.field.field.i and this will return the ITypeBinding corresponding to the primitive type int. I released this code in HEAD. Let me know if this is good enough for you. If this is fine, I will close this PR as FIXED.
Im not sure if I fully understand the current limitation. Here is what I expect to get. Can you please annotate this example QualifiedName(f.f.f.i): note changed field to f to avoid conflicts with term field - this.resolveBinding: IVariableBinding for i - this.resolveTypeBinding: int - this.name.resolveBinding: IVariableBinding for i - this.name.resolveTypeBinding: int - this.qualifier: see below QualifiedName(f.f.f) - this.resolveBinding: IVariableBinding for f - this.resoveTypeBinding: TestNestedRead - this.name.resolveBinding: IVaraibleBinding for f - this.name.resolveTypeBinding: TestNestedRead - this.qualifier: see below QualifiedName(f.f) - this.resolveBinding: IVariableBinding for f - this.resoveTypeBinding: TestNestedRead - this.name.resolveBinding: IVaraibleBinding for f - this.name.resolveTypeBinding: TestNestedRead - this.qualifier: see below SimpleName(f) - this.resolveBinding: IVariableBinding for f - this.resoveTypeBinding: TestNestedRead
In the case of nested qualifications: isn't QualifiedName.resolveBinding == QualifiedName.name.resolveBinding and QualifiedName.resolveTypeBinding == QualifiedName.name.resolveTypeBinding.
This is quite simple. QualifiedName(f.f.f.i): note changed field to f to avoid conflicts with term field - this.resolveBinding: IVariableBinding for i - this.resolveTypeBinding: int - this.name.resolveBinding: IVariableBinding for i - this.name.resolveTypeBinding: int - this.qualifier: see below All these requests can be performed without a problem. This is the problem. QualifiedName(f.f.f) QualifiedName(f.f) SimpleName(f) For these three names, I cannot retrieve the right binding. The problem is that I have only one compiler's qualifiedNameReference for all those. Then I cannot retrieve the right binding for a subpart of the qualified name, because I don't know which binding I have to return. I don't know if I am very clear, but the point is that the only bindings you can retrieve are on the qualifiedname and its name part, but not on any subpart of the qualified name.
But this is something we need. Otherwise refactoring a field that is used in this way fail (for example Self Encapsulate field). The current compiler AST gives us those bindings in the field QualifiedNameReference.otherBindings. So I don't really understand why we can't get them in the new AST. One idea would be to walk the parent relationship, counting them until you reach the node pointing to the QualifiedNameReference and then using this counter (or a transformation) as an index into QualifiedNameReference.otherBindings.
I understand how crucial it is for you to get these bindings. I am working on it. I will use the walking strategy you described to hopefully be able to retrieve the right bindings. I am working on that today and it should be fixed by the end of the day. Thanks for your feedback.
Thanks for the quick response !
Fixed and released in HEAD. Added ASTConverterTests>>test0227/test0228/test0206.