Community
Participate
Working Groups
Using 0508, I got invalid imports after doing an "organizing imports" action. I isolated a simple test case: First class: [package p1; public class A { public static void foo() { } }] Second class: [package p2; public class A { public static void foo() { } }] Third class: [package p3; import p1.*; public class B { public static void bar() { p2.A.foo(); } public static void main(String[] args) { A.foo(); } }] The "Organizing imports" action is done on that last class. The result is: [package p3; import p2.A; public class B { public static void bar() { p2.A.foo(); } public static void main(String[] args) { A.foo(); } }] Having only p2.A is incorrect, because the line A.foo() was actually referring to p1.A.foo() and not p2.A.foo(). I checked that the DOM/AST binding resolution returns two different bindings for the two names (p2.A or A) and (A in A.foo()). We have p1.A and p2.A, but the resulting import contains only p2.A. So I wonder why p1.A has been removed. Futhermore I think that fully qualified name should never be investigated in this case. p2.A is enough and there is no need to have this import in the import's declarations. In this case, having p1.A and p2.A would result in a conflict and this is why p2.A has been used as a fully qualified name reference in the source. I think it is crucial that "Organize imports" handles this case properly. I found it in the JDTCore sources and this led to a message could not be retrieved. So even if the code compiles fine, the "Organizing imports" had a side-effect on the runtime. In order to be useful and safely use, this needs to be fixed. This is why I set the severity to major.
When looking at qualified names like 'p1.A.foo()', only the very first qulifier ('p1') is examined (and imported if it's a type binding) The problem here is that when asking the SimpleName node p1 for it's binding the type binding of p1.A is return. This is a bug, no? I was thinking it should return a package binding.
Fix and released in HEAD.