This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 27930 - Organize imports removes imports from "default" package
Summary: Organize imports removes imports from "default" package
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.1   Edit
Hardware: Other Windows 2000
: P3 normal (vote)
Target Milestone: 2.1 M4   Edit
Assignee: Martin Aeschlimann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-12-09 07:57 EST by Roel De Meester CLA
Modified: 2002-12-10 06:26 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Roel De Meester CLA 2002-12-09 07:57:11 EST
Since 1.3 it is no longer 'allowed' to work with classes in the 'default' 
package. (i.e no package declaration).


As a consequence eclipse no longer allows imports from such packages and removes 
them whenever an 'organize import' is requested.


Our project (real-time lightweight small memory-print) is based on a JVM that 
has been developed in-house an is based on 1.1.8. And yes.. there are classes 
that are in the default package. There is one class (orb) in particular that is 
used in about 60% of all our classes.


It very annoying that  eclipse automatically removes the import orb; statement 
from all these classes. You don't even have to call a organize import. If you do 
a code completion that adds a new import statement, this will also remove the 
very important import statement. 


PLease, please  supply an option in the preferences to prevent the clean up of 
these imports.


Many thanks.
Comment 1 Martin Aeschlimann CLA 2002-12-10 04:39:27 EST
Which build are you using?
It's the other way round: So far Eclipse never added imports to types in 
default package, since some weeks ago it does. We don't force any 1.4 
compatibility with organize imports (I thought it was 1.4 , not 1.3 which has 
the new rule), you will have to fix your code anyways if you use classes in the 
default packages and want to run on 1.4.

If you are already using the latest integration builds (> M3), and still have 
the problem, please reopen the bug with some steps.
Comment 2 Roel De Meester CLA 2002-12-10 05:06:14 EST
1) You're right it is 1.4 which has the new rule.. not 1.3


2) We are working with 1.1.8 and we'll never move to 1.4. As stated before, i'm 
working on a home-made JDK pased on 1.1.8. We don't plan to rewrite this JVM. 


3) It is still in M3 (which i'm using now).. But has not always been there. 
Somewhere will making 2.0 this 'feature' slipped in.




Maybe a didn't express myself very clear.. i'll do it again with an example




Step 1. Create a class in the default package


----


public class DefaultClass {


}




Step 2. Create some class using that defaultClass


---


package myPack;


import DefaultClass;




public class AClass {


	public static void main(String[] args) {


        DefaultClass defaultClass = new DefaultClass();


    }


}


------




Step 3a. (Manual way)




On the AClass perform a Organize Imports.




-> It will remove the line  "import DefaultClass"  


-> as a result AClass has compiler errors.




Step 3b (Indirect way)


Place your cursor somewhere in the main Class. Type 'Colo' and press Ctrl+Space 
to call code completion. Select java.awt.Color. The line 'import java.awt.Color' 
is added, and at the same time the line 'import DefaultClass' is removed.






Bug 3a, is not so annoying since i don't often call 'organize imports' 


Bug 3b, though is worse since i use codecompletion very often to added never 
used Class references..




Comment 3 Martin Aeschlimann CLA 2002-12-10 05:17:04 EST
The feature is in the latest integration build (not yet in M3).
I tested your scenario, it works now!
Comment 4 Roel De Meester CLA 2002-12-10 06:26:34 EST
I just checked with 


Version: 2.1


Build id: 200212041234




---- 


The bug is indeed fixed, but not perfect.




What i get when i do organize imports is that




import DefaultClass;




is replaced by




import.DefaultClass;   //A dot is added!!






Minor bug.. we're almost there.