This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 122109 - Implement Optimize Imports
Summary: Implement Optimize Imports
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: All All
: P1 blocker with 12 votes (vote)
Assignee: Jan Lahoda
Depends on: 201730
Blocks: 183703
  Show dependency tree
Reported: 2007-11-16 10:58 UTC by Jan Becicka
Modified: 2011-09-07 15:47 UTC (History)
7 users (show)

See Also:
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description Jan Becicka 2007-11-16 10:58:07 UTC
Implement Optimize Imports.
Comment 1 adam_myatt 2008-09-13 00:03:45 UTC
My 2 cents... Rather than add a new feature, we could simply have the Fix Imports feature modified. Fix Imports adds 
missing imports and removes unused imports. It would be nice if it also automatically re-ordered the import statements 
on each invocation so they are in the proper and sorted order. Many tools like checkstyle, pmd, etc. check that the 
imports appear in sorted order. If you have a class with imports that are completely out of order and you delete all 
the imports, trigger the Fix Imports and they are all re-added, but in the correct order. The Fix Imports feature 
should re-order the imports that are already there, without having to delete them all and triggering fix imports.
Comment 2 ulfzibis 2008-09-13 15:33:12 UTC
IMHO these issues should be taken into account here:

Issue 42157 {Make IDE Settings movable without import}
Issue 55647 {Allow user to choose which version to import settings from}
Issue 129611 {Correct modified module links in library descriptors while importing settings for new NB installation}

Comment 3 arneand 2008-09-23 07:18:05 UTC
I support the initiative, but it would be useful to have the option of turning it off, since it would cause "false 
positives" in your version control, and may not be desirable.

On the other hand, it would also be nice to be able to hook it onto the 'Save ' action, so it will fix your imports 
when you save the file.
Comment 4 fommil 2009-05-05 14:15:59 UTC
Don't forget about static imports, be sure to agree with issue 122109's modifications to SourceUtils.add*Imports (if that patch is accepted)
Comment 5 _ rkubacki 2009-10-05 22:19:43 UTC
Seriously, P3 TASK does not sound right and I am afraid this will never be done.

[65cat] discussion touched the details that some companies are very sensitive to code conventions. Those will frequently
import order
wildcard imports allowed or not
no unused imports

Obviously this can become a blocker for an adoption if other tools have that support.
Comment 6 David Strupl 2009-10-06 08:37:48 UTC
This has been mentioned in the plan here I will ask Max but I guess we might move
it to the next release since we are post feature freeze/beta now and this sounds like a bigger feature (if I understand
it right).
Comment 7 _ rkubacki 2009-10-06 21:50:32 UTC
Thanks for the feedback.
Comment 8 nigjo_iqn 2010-04-07 09:32:30 UTC
I've done a first version for this:

It's an unsigned nbm and very less tested but it works for me.

Comment 9 entonio 2010-09-29 17:21:59 UTC
Thanks Jens. Works great.


- If the order is already correct, it does nothing (should separate the groups if they aren't already).

- It would be great if 'Fix imports' was automatically called before organizing, that way one keystroke would be enough to fix and organize.

- There could be a special package group representing 'all the other imports', which could be placed in any position in the list (so that f.i. java.* could be after all the other imports).

Comment 10 Jan Becicka 2011-01-21 13:34:36 UTC
see also 183703
Comment 11 Dusan Balek 2011-08-29 16:24:28 UTC
Implemented in jet-main.
Comment 12 Quality Engineering 2011-09-01 14:20:48 UTC
Integrated into 'main-golden'
User: Dusan Balek <>
Log: Issue #122109: Implement Optimize Imports - fixed.