Community
Participate
Working Groups
20021001 Similar as bug 24406, again for quick fix: Would it be possible to get the FieldAccess bindings to non-visible / non static fields? public class C { private int fCoo; } public class D { public static void goo(C c) { fCoo= 1; super.fCoo= 1; C.fCoo= 1; c.fCoo= 1; } }
Same for types: public class C { private class CInner { } } public class D { public static void goo() { CInner c; } }
In this case, I cannot do anything. The binding of the SingleNameReference is null and because of the static context I cannot retrieve a scope to do the resolution. So no hope in this case. Ok to close as WONTFIX?
I got it working by rudely (and naivly) removing binding.isValidBinding() in DefaultBindingResolver.resolveName, line 218 // this is a variable or a field Binding binding = singleNameReference.binding; if (binding != null) { << removed here and getVariableBinding, line 686 if (variableBinding == null) { << removed here return null; } What do you think?
Sorry forgot another one at line 123.
I will investigate, but I don't want to hack the code in order to have one or two quickfixes ok. We have to be able to explain why something is not resolvable. Bug 24453 is a priority. I will have a look again at this one, but I don't see how removing null checks can improve something. In your first test case, the binding of the single name reference is null. So I think it is safe to return null at this point, isn't it?
Oops, bug in my code example: public class D extends C { Otherwise it can only be null, of course, as you say. If the 'extends' is there, the DefaultBindingResolver has bindings but returns null as the binding.isValidBinding returns false: The binding has error code ProblemReasons.NotVisible or ProblemReasons.NonStaticReferenceInStaticContext.
I was talking about this example: public class C { private int fCoo; } public class D { public static void goo(C c) { fCoo= 1; super.fCoo= 1; C.fCoo= 1; c.fCoo= 1; } } In this case there is nothing I can do. I simply don't have a binding. I will investigate the second example.
In this case, public class C { private int fCoo; } public class D { public static void goo(C c) { fCoo= 1; } } There is nothing I can do. This case is fixed: public class C { private class CInner { } } public class D { public static void goo() { CInner c; } } And will try the different other cases for: super.fCoo= 1; C.fCoo= 1; c.fCoo= 1;
super.fCoo= 1; FAIL C.fCoo= 1; OK c.fCoo= 1; OK Closed as FIXED. The two corner cases: fCoo= 1; super.fCoo= 1; won't be fixed. Fixed and released in HEAD. Regression tests added.
Thanks a lot! My code missed the 'extends C' statement. Can you try this? public class C { private int fCoo; private class CInner { } } public class D extends C { public void goo(C c) { fCoo= 1; super.fCoo= 1; C.fCoo= 1; c.fCoo= 1; C.CInner a; CInner b; } } I took the latest code from HEAD. fCoo= 1; fails and C.CInner a; CInner b; fail as well. Sorry for the trouble. But the more bindings we get, the more we can offer when working on almost correct code. So this thing is really helpful.
Another case: Can't resolve coo2() in the constructor C() public class C { private C() { this(coo2()); } private C(int i) { } private int coo2() { return 7; } }
Please open different PRs for such problems. It is not trivial to cover all test cases added in a single PR. I close this one and please open a new one for the member visibility and for the method invocation in the constructor invocation. As I said before, fCoo= 1; won't be fixed. In this case I don't have any binding on which I can do some lookup.