Bug 122109 - Implement Optimize Imports
Implement Optimize Imports
Status: RESOLVED FIXED
Product: java
Classification: Unclassified
Component: Source
6.x
All All
: P1 with 12 votes (vote)
: 7.1
Assigned To: Jan Lahoda
issues@java
:
Depends on: 201730
Blocks: 183703
  Show dependency treegraph
 
Reported: 2007-11-16 10:58 UTC by Jan Becicka
Modified: 2011-09-07 15:47 UTC (History)
7 users (show)

See Also:
Issue Type: ENHANCEMENT
:


Attachments

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
include:
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 http://wiki.netbeans.org/EditorPlan68. 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: http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=27296

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

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

3 comments:

- 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).

Thanks!
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.

http://hg.netbeans.org/jet-main/rev/c604329f2888
Comment 12 Quality Engineering 2011-09-01 14:20:48 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/c604329f2888
User: Dusan Balek <dbalek@netbeans.org>
Log: Issue #122109: Implement Optimize Imports - fixed.


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo