Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 146122

Summary: [organize imports] Organize Imports orders imports incorrectly
Product: [Eclipse Project] JDT Reporter: Simon Archer <sja.eclipse>
Component: UIAssignee: Martin Aeschlimann <martinae>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: villane
Version: 3.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Simon Archer CLA 2006-06-08 17:29:08 EDT
Using Eclipse 3.2 RC7

Organize Import incorrectly orders imports.  Given the following Java resources

  Package: a
	Java: A.java

  Package: com.ibm.simona
	Java: Foo.java

  Package: com.ibm.z
	Java: Z.java


And given the following code that has had "Organize Imports" performed upon it.  Take special note of the import order.

  package com.ibm.z;

  import a.A;

  import com.ibm.simona.Foo;

  public class Z {
	private A a;
	private Foo foo;
  }

My Java > Code Style > Organize Imports preferences are set to the defaults.  I would have expected the import order to be:

  import com.ibm.simona.Foo;
  import a.A;

In fact, this is what happens in a much earlier version of Eclipse that I've used.
Comment 1 Erkki Lindpere CLA 2007-07-16 03:56:31 EDT
This has received no attention for a year? Organize imports ordering is still broken in 3.3. Firstly, the settings are not respected:
1) The group "*" for unmatched packages are always first no matter what settings
2) "org" packages seem to always be last no matter what settings

Also, settings export/import doesn't work when the "*" group is present. Also, export/import should also save the counts (# needed for .*) and other settings.

Maybe this seems like an unimportant issue (who looks at imports anyway?), but when using Eclipse with other tools on the same project, it becomes important that all tools behave in an expected manner.
Comment 2 Martin Aeschlimann CLA 2007-07-16 10:03:20 EDT
I wasn't aware of the import/export problems. I filed bug 196646. Please file separate bugs for the issues with the 'unmatched groups'. I don't think this bug has anything to do with it.

When fixing bugs we have to prioritize. But I hope I will be able to have a look at this soon. Sorry.
Comment 3 Martin Aeschlimann CLA 2008-05-06 09:27:08 EDT
I filed bug 230391 for issue 1 of comment 1.
I can't reproduce comment 2. 'org' seems to be correctly matched if you add such a group.
Comment 4 Martin Aeschlimann CLA 2008-05-06 09:30:26 EDT
The scenario in comment 0 works as intended. If you don't have the 'all unmatched' group in you import order, the unmatched imports will be place to the (alphabetically) closest matching group.
The solution is to add the 'unmatched imports group'. With the fix for bug 230391 this should work again.