Bug 412929 - [organize import] Adding a type results in adding a package and later does not honor order
Summary: [organize import] Adding a type results in adding a package and later does no...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 normal with 1 vote (vote)
Target Milestone: 4.5 M6   Edit
Assignee: John Glassmyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 430303
  Show dependency tree
 
Reported: 2013-07-14 23:22 EDT by JasonMing CLA
Modified: 2015-03-05 14:55 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.