tags:

views:

247

answers:

2

Is there any way to run the Eclipse cleanup rules on a whole set of classes/packages instead of individual classes?

(Preferences > Java > Code Style > Clean Up)

I right-click on the class and invoke Source-Clean Up, but it sure would be nice to invoke it on a set of classes.

+5  A: 

I'm not sure from your question if you're right clicking in the Editor or in one of the other views. However, if you select multiple multiple source files or folders in the Package Explorer you can right click in the Package Explorer and do Source -> Clean Up. The title in the first page of the Clean Up wizard should indicate how many files are going to be cleaned (e.g. "Cleaning up 20 files in 1 project")

mikej
Note that there are two separate places to configure cleanup XXXX Java->Code Style->Cleanup (explicit cleanup as mikej mentions) and Java->Editor->Save Actions (cleanup on file save as jjnguy mentions) [I'm duping this comment on both actions as it's not well-known and applies to both]
Scott Stanchfield
+1 Thanks, I was looking for the same solution, but I was trying to right click on a higher level package (which had only packages and no sources directly as children). But select multiple "low level" packages fits me.
Baztoune
+1  A: 

I suspect what you really want to do is apply a "code cleanup" to ALL of your java source files, not just ones that you selected manually.

Here's how:

1) In the Packages view (or the Package Explorer view) change your "Package Presentation" from "hierarchical" to "flat". There's a little upside down triangle in the top right corner of each view that lets you change this setting.

2) Now when you navigate to your source code directory you should see ALL the packages and sub packages and sub sub packages that contain your java source files, all presented together in one (possibly huge) list.

3) Of course, when you have a huge list like this, you can easily select all the packages (left-click the first one, then shift left-click the last one).

4) Then, right click on the selection, and go to "Source->Clean Up..." (or any other "Source" submenu item, like "Organize Imports") and the dialog that pops up will tell you how many source files it is about to change.

Hope that helps!

Xanatos