Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 352891 - Organize imports does not work in accordance to preferences
Summary: Organize imports does not work in accordance to preferences
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows 7
: P3 minor with 6 votes (vote)
Target Milestone: 4.5   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-22 12:54 EDT by Kasper Nielsen CLA
Modified: 2016-01-08 16:46 EST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kasper Nielsen CLA 2011-07-22 12:54:33 EDT
Build Identifier: 20110615-0604

I've seen some times that imports are not ordered according to the order registered in Java->Code Style->Organize

Reproducible: Always

Steps to Reproduce:
1. Using the default ordering of
java
javax
org
com

Organize the following imports. Notice that the junit import is on top instead of the org import

import junit.framework.TestCase;

import org.w3c.dom.Comment;

public class Test {
    Comment c = null;
    TestCase fs = null;
}

2.
If I change the order to (switch org and javax) it imports the classes in the right order
java
org
javax
com

import org.w3c.dom.Comment;

import junit.framework.TestCase;

public class Test {
    Comment c = null;
    TestCase fs = null;
}

I have only been able to verify it with imports from the junit package.
Comment 1 Olivier Thomann CLA 2011-08-23 11:51:14 EDT
The "best" match for junit is considered to be "javax". So the junit entry is located relative to the javax entry.
Why do you expect "import org.w3c.dom.Comment;" before "import junit.framework.TestCase;" ?
Comment 2 Jacques Stadler CLA 2015-03-20 10:14:58 EDT
Hi

I have the same issue.

I would expect that all the entries in the default ordering configuration are at the top. And after all the default ordering entries all others appear. 

So for default ordering:
java
com

I get:
import java.util.List;

import org.junit.Test;

import com.mycompany.AnyClass;


But I would expect:
import java.util.List;

import com.mycompany.AnyClass;

import org.junit.Test;
Comment 3 Aleksandr Ivanov CLA 2015-07-21 13:48:10 EDT
I would like to stress this problem again.
Real problem is when people in same team work in different IDEs: Eclispe, Idea, NetBeans,... - and each IDE try to fix imports order. It results in lots of merging conflicts.
It becomes quite difficult to have imports organized with no pain.
When IDE prevents people from effective collaboration, teams are forced to use one IDE, and it is not always Eclipse.

I also would like to comment on Oliver's post:
>> The "best" match for junit is considered to be "javax". So the junit entry is located relative to the javax entry.

When I adjust "Organize Imports" settings (add or edit) Eclipse does not allow to enter something like regular expression, it forces me to select valid package. So "best match" between junit and javax is not acceptable. It should be "starting with" partial match.

"Organize Imports" should have a predictable outcome, now it is not (or very not obvious).
Comment 4 Ruslan Diachenko CLA 2015-07-25 16:28:10 EDT
Here https://github.com/checkstyle/checkstyle/issues/1448#issuecomment-123830773
is the analysis of the problem that shows that Eclipse has a problem in such a  simple option.
Comment 5 Aleksandr Ivanov CLA 2015-07-27 05:21:35 EDT
I have just updated to Eclipse Mars version and it looks like the problem is solved.
Comment 6 Markus Keller CLA 2016-01-08 16:46:59 EST
(In reply to Aleksandr Ivanov from comment #5)
> I have just updated to Eclipse Mars version and it looks like the problem is
> solved.

Thanks, marking as FIXED.