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

Bug 412929

Summary: [organize import] Adding a type results in adding a package and later does not honor order
Product: [Eclipse Project] JDT Reporter: JasonMing <JasonMing>
Component: UIAssignee: John Glassmyer <eclipse>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, eclipse.sprigogin, eclipse, markus.kell.r
Version: 4.4   
Target Milestone: 4.5 M6   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 430303    

Description JasonMing CLA 2013-07-14 23:22:40 EDT
Currently, as document described (http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fpreferences%2Fjava%2Fcodestyle%2Fref-preferences-organize-imports.htm), the organize import feature does only match the prefix of imports, but not the qualified class name.

If I want to make some class always be the first import in the file, like the android's "R" class, it is not possible.

I hope the organize import feature can handle the exact class and put them to the position I set.
Comment 1 Dani Megert CLA 2013-07-15 07:13:27 EDT
When adding a new entry via New... button, one can already select a type, but that ends up as a package in the list. And later, its order is not honored.
Comment 2 John Glassmyer CLA 2013-12-03 11:25:43 EST
Currently you can specify a qualified type name in your Organize Imports order because a type can be an import container.  I.e. if you have "com.foo.Class" in your import order, then Organize Imports should place "import com.foo.Class.Foo;" and "import com.foo.Class.Bar;" in that spot.

A question: If you have both "com.foo" and "com.foo.Class" as entries in your import order, should "import com.foo.Class;" match "com.foo" (in which it is contained) or "com.foo.Class" (which it is)?

I guess the expected organized imports, given an import order configured like this

  com.foo.Class
  java.util
  com.foo

would be

  import com.foo.Class;
  import com.foo.Class.*;
  import com.foo.Class.Foo;

  import java.util.ArrayList;

  import com.foo.OtherClass;

Note that I am currently rewriting ImportRewriteAnalyzer and I should be able to implement this change there.
Comment 3 Dani Megert CLA 2014-05-19 11:18:29 EDT
(In reply to John Glassmyer from comment #2)
> Currently you can specify a qualified type name in your Organize Imports
> order because a type can be an import container.  I.e. if you have
> "com.foo.Class" in your import order, then Organize Imports should place
> "import com.foo.Class.Foo;" and "import com.foo.Class.Bar;" in that spot.
> 
> A question: If you have both "com.foo" and "com.foo.Class" as entries in
> your import order, should "import com.foo.Class;" match "com.foo" (in which
> it is contained) or "com.foo.Class" (which it is)?

The latter.
Comment 4 Dani Megert CLA 2014-06-18 06:45:41 EDT
John, can I assign this bug to you?
Comment 5 John Glassmyer CLA 2014-06-18 15:40:46 EDT
(In reply to Dani Megert from comment #4)
> John, can I assign this bug to you?

Sure, please do.
Comment 6 Markus Keller CLA 2015-03-05 14:55:36 EST
Fixed via bug 430303.