Luigi is a passionate software developer working in Java since 2000. In 2001 he co-founded the Java User Group Torino, the first local JUG in Italy. Quickly after that, many other JUGs have born in Italy following JUG Torino's example. Since some years now, he is working as free lance software consultant between Italy, Germany, UK and Switzerland, on several industries. His personal interests include software, science fiction books and movies, traveling, photography and good food. Luigi is a DZone MVB and is not an employee of DZone and has posted 19 posts at DZone. You can read more from them at their website. View Full User Profile

Eclipse Save Actions

  • submit to reddit

I recently started using a feature in Eclipse 3.6.1 that I didn't notice before: the "Save Actions".
Basically you can configure some actions that will be done automatically when you save a Java source. Some of them are really useful, like Organizing the imports, adding 'final' to private member instances, etc. Here the screen-shot of it, with my preferences:

Eclipse Save Actions

Eclipse Save Actions

From now on, nomore unused imports and better immutable classes.



Your rating: None
Published at DZone with permission of Luigi Viggiano, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)



Amir Laher replied on Fri, 2011/02/11 - 4:00am

Hi Luigi, I also like that feature ...

I have a few more checked, but it's not important: 'organize imports' is the biggest one for me!

I'll share them with you:

  •     Change non static accesses to static members using declaring type
  •     Change indirect accesses to static members to direct accesses (accesses through subtypes)
  •     Convert control statement bodies to block
  •     Convert for loops to enhanced for loops
  •     Remove unnecessary parentheses


Damien Lepage replied on Fri, 2011/02/11 - 11:05am

I would recommend one more usage: code formatting!

That's the reason I still put Eclipse configuration files into my source code repository, although I use Maven which could technically allow developers to use the IDE of their choice.

All the developers in my team use Eclipse, so whenever they save a file, our formatting rules is applied. Then, when comparing different versions of a file, we only see real differences , never differences due to code re-formatting.

Also, watch out about one problem with auto organized imports. Sometimes, you want to do a quick edit on a file which doesn't compile in Eclipse yet, because of some missing generated code, or library in your Maven repo. You know your project build will work because your build tool will take care of generating the code or downloading the library. But Eclipse doesn't know that and will remove the import statements which it doesn't find. So, it will break your build. That bothered me a few times. You need to run your build once, then refresh your project in Eclipse, then you can make your change.

To avoid that, I temporarily disabled the feature a couple of times, and even edited some Java code in Notepad++ rather than Eclipse.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.