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 25377 - Batch "fix imports" and "format" for entire project
Summary: Batch "fix imports" and "format" for entire project
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 3.x
Hardware: All All
: P2 blocker with 15 votes (vote)
Assignee: Jan Lahoda
Keywords: PLAN
: 150633 (view as bug list)
Depends on:
Blocks: 179993 201564
  Show dependency tree
Reported: 2002-07-07 18:50 UTC by jnash67
Modified: 2011-09-03 14:29 UTC (History)
13 users (show)

See Also:
Exception Reporter:

module containing the solution (19.72 KB, application/x-compressed)
2008-10-31 21:29 UTC, phry
most recent version (15.01 KB, application/x-compressed)
2009-10-21 23:01 UTC, phry

Note You need to log in before you can comment on or make changes to this bug.
Description jnash67 2002-07-07 18:50:52 UTC
The import manager is really nice. A very useful feature 
would be to have it import manage an entire project rather 
than just a file at a time.
Comment 1 Marek Grummich 2002-07-22 10:50:16 UTC
Set target milestone to TBD
Comment 2 wqtnetbeans 2005-04-01 17:43:56 UTC
Changed version to "current" (previously it was 3.3.2).
Comment 3 Vitezslav Stejskal 2007-02-22 00:11:22 UTC
Ideally we would like the 'Fix imports' action to be available for a package, a
sources node and the entire project.
Comment 4 Jesse Glick 2007-02-22 01:06:32 UTC
Probably something that would fit comfortably into the Jackpot UI, too.
Comment 5 _ gtzabari 2007-02-22 14:09:32 UTC
A related requirement is to remove unused imports on the same scope (project,
package, etc).
Comment 6 Geertjan Wielenga 2008-10-14 10:48:42 UTC
Note that there are students who are thinking about working on this project:
Comment 7 Vitezslav Stejskal 2008-10-20 13:32:11 UTC
*** Issue 150633 has been marked as a duplicate of this issue. ***
Comment 8 phry 2008-10-31 21:29:34 UTC
Created attachment 73022 [details]
module containing the solution
Comment 9 phry 2008-10-31 21:33:31 UTC
I attached a module providing the requested feature.
Please look over it and tell me what else I have to do to commit this to the NetBeans sources correctly.
Comment 10 Geertjan Wielenga 2008-11-03 17:10:10 UTC
CC-ing Tonda, Jaroslav, and David. Guys, one of the students has fixed this issue and has attached the patch above.
Great, isn't it? Can the code be reviewed and more suggestions made to him?
Comment 11 Geertjan Wielenga 2008-11-05 12:46:55 UTC
Adding myself and Tonda to the cc.
Comment 12 Jan Lahoda 2008-11-05 22:12:05 UTC
Great! Ideas for improvements:
-the reformat action block AWT (repainting) during reformatting the sources. This is not correct - the reformatting
should run on background, and ideally there should be a progress dialog with Cancel. I might be a good idea to first
gather all FileObjects that should be processed and then process them.
-the current impl. of the action seem to allow reformatting only of one folder - might be better if it directly allowed
reformatting of (one or more) Projects, SourceGroups, packages/folders and files, and maybe combinations of thereof. You
may get some inspiration in contrib/javahints module, in BatchApply and BatchApplyAction classes:
-replace EditorCookie.saveDocument() with (note that the SaveCookie is not be in the lookup if the
file is not modified).
-it would be good to clarify what should do the "fix all imports on package" action. Currently, if there will be several
files with unresolved imports, it may cause several "Fix All Imports" dialogs (one for each file), which is probably not
very good. Maybe the semantics should be "remove all unused imports"?
-in JavaFixImportsAction you should keep the opened document in a local variable, otherwise it might get GCed prematurely.
-might be good to implement the discovery process (finding files that should be modified) only once for both actions.
-I personally do not like the Source submenu of the folders very much. I guess that the placement of the action should
be discussed with HIE (adding jrojcek on CC). Also, if the "main UI elements" are going to be modified, there needs to
be a UI review (before merging to trunk):
-it should be checked whether a new class(es) are loaded on startup - the performance team probably wouldn't like that.
Comment 13 phry 2008-11-23 18:28:37 UTC
I'm nearly finished with most of your points but I can't manage to add my menu to all file's (including projects etc.) 
contextual menues (yes, we can discuss this, but right now it seems to me the most natural way) - can you give me a 
hint on this?
Comment 14 Geertjan Wielenga 2008-12-01 21:49:07 UTC
I think there is a folder called "any", which applies to all folders and files, but I could be wrong. Have you solved
the problem in the meantime?
Comment 15 sreimers 2008-12-15 09:18:18 UTC
For Projects use

<folder name="Projects">
        <folder name="Actions">
            <file name="your-action.instance">
                <attr name="position" intvalue="yourPosition"/>

for packages / folders use

    <folder name="Loaders">
        <folder name="folder">
            <folder name="any">
                <folder name="Actions">
                    <file name="your-Action.instance">
                        <attr name="position" intvalue="yourPosition"/>
Comment 16 Geertjan Wielenga 2009-08-24 16:18:22 UTC
Can this be integrated by jlahoda (or someone) even though the contributor hasn't completed it 100%? I.e., can't we do
the few things that are left to do and integrate this code so that a really nice feature can be added (and a P2 solved
and a student project integrated into the NetBeans sources)?
Comment 17 phry 2009-08-26 03:15:28 UTC
I still have a newer version than what is uploaded (just never managed to do the "correct" implementation into the 
menus & contacting the gui team et cetera.) - I will dig it up from my backups and post it here in the next days so 
that my sucessor will have less work.
hope this helps & sorry for not finishing it myself, just can't find the time :/
Comment 18 phry 2009-10-21 23:01:31 UTC
Created attachment 89894 [details]
most recent version
Comment 19 phry 2009-10-21 23:02:19 UTC
hi again,
sorry it took so long. this should be my most recent version.
Comment 20 Jiri Kovalsky 2009-10-22 05:24:06 UTC
Although this can't be integrated now, will you have time Honzo to take a look at this after 6.8 is branched? Thanks!
Comment 21 roti 2010-08-17 08:56:58 UTC
Is it possible to add this feature for 6.10?
Comment 22 Jan Lahoda 2011-09-02 07:30:05 UTC
There are two new features in 7.1: organize imports (for one file, bug #183703) and Inspect and Refactor that allows to run Java editor hints on projects/folders. So I added a Configuration to this dialog that performs Organize Imports on selected scope:
Comment 23 _ gtzabari 2011-09-02 12:05:25 UTC
Just curious: what happened to allowing code-format on multiple files (as implied by the title)?
Comment 24 Jan Lahoda 2011-09-02 12:19:19 UTC
Thanks for noticing that, I have created enhancement #201564 for reformatting whole project.
Comment 25 Quality Engineering 2011-09-03 14:29:21 UTC
Integrated into 'main-golden'
User: Jan Lahoda <>
Log: #25377: adding Organize Imports configuration.