Community
Participate
Working Groups
Build ID: M20080911-1700 Steps To Reproduce: Please Organize Imports on class Bug. See the result is illegal since a needed static import is wrongly removed. More information: --------------- bug/Bug.java ------------- package bug; import static bug.CaseType.all; import static bug.ShareLevel.all; import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.widgets.Composite; import bug.CaseType; import bug.ShareLevel; class Bug{ void run(Wizard wizard){ wizard.addPage(new WizardPage("pickCase",null,null){ public void createControl(final Composite parent){ for(CaseType cat:all()) cat.hashCode(); class Share{ Share(final ShareLevel sharing){ sharing.hashCode(); } } new Share(all); }}); } } ---------------------- bug/CaseType.java ------------ package bug; enum CaseType{ one; static CaseType[]all(){return null;} } ---------------- bug/ShareLevel.java ---------------- package bug; enum ShareLevel{all}
Looks like a bug in the org.eclipse.jdt.core.dom.rewrite.ImportRewrite. Paste the following to get the test case quicker: package bug; import static bug.CaseType.all; import static bug.ShareLevel.all; import bug.CaseType; import bug.ShareLevel; class Bug{ public void createControl(){ for(CaseType cat:all()) cat.hashCode(); class Share{ Share(final ShareLevel sharing){ sharing.hashCode(); } } new Share(all); }; } package bug; enum CaseType{ one; static CaseType[]all(){return null;} } package bug; enum ShareLevel{all}
Created attachment 155406 [details] Patch for the problem
Jay, please review the patch and add regression tests.
Created attachment 155715 [details] Updated patch with regression test The first patch looks alright. Ideally it would have been better to have the static import comparison in the ImportRewrite#compareImport(). However, I do see that we will have to move few things around. So left it that way and made one minor change (a variable name change) and added a regression test.
Created attachment 156258 [details] Proposed fix In the line: (this.importsKindMap.get(curr.substring(1)).equals(this.importsKindMap.get(qualifier + "." + name)))), is it sure that this.importsKindMap.get(curr.substring(1) cannot return null ? I don't like to see 's' used for a prefix instead of using the constant field STATIC_PREFIX. Also all strings should be either externalized or tagged with the NON-NLS tag. I slightly change the patch. Jay, let me know whay you think. If everything is ok, I'll release early next week.
Released the last patch for 3.6M5. Added regression test: org.eclipse.jdt.core.tests.rewrite.describing.ImportRewriteTest#testBug252379
Verified for 3.6M5 using Build id: I20100122-0800
Verified.