Skip to content

Good to Know Eclipse Features

SWP-Comp-Deathk edited this page Apr 27, 2013 · 2 revisions

Here are some Good-to-Know-Eclipse-Features

All of these features can be enabled per project or workspace wide. To set them workspace wide go to Window -> Preferences To set them per project right click the project and go to Properties.

Auto formatting your code

You can enable save actions in eclipse. These actions are triggered whenever you save your code. There are nearly 50 different save actions you can enable or disable, and there are even more you can define by yourself.

Here is how to set them up:

  • go to Window -> Preferences
  • go to Java -> Code Style -> Formatter
  • Select the code formatter you want to use (for K&R indentation style use Eclipse [builtin])
  • Hit apply
  • go to Java -> Editor -> Save Actions
  • Check Perform the selected actions on save
  • Check Format source code - Format all lines
  • Check Organize imports
  • Check Additional actions
  • Click on Configure
  • In Code Organizer check Remove trailing whitespace from All lines
  • In Code Style check Use blocks in if/while/for/do statements - Always
  • In Member Access check Use this qualifier for field access - Always, Use this qualifier for method access - Always
  • In Missing Code check all options
  • In Unnecessary Code check Remove unused imports, Remove unused local variables, Remove unnecessary casts
  • Click on ok
  • Click on ok once again

Do not forget Javadoc

Javadoc is essential for good documentation. But a programmer is a lazy being and will stop writing javadoc even if he did it the first week.

To force javadocs do the following:

  • Go to Window -> Preferences
  • Go to Java -> Compiler -> Javadoc
  • Set the warning levels to error
  • Set the visiblitiy to private
  • Set Missing tag description to Validate all tags
  • Click ok and confirm your selection

Javadoc

Always use Ant to build

Instead of using eclipse's automatic build options you can set eclipse to always use the ant build.xml for building and executing your code. Go to your Project Properties and select Builders. Create a new Ant Builder and fill in the options needed.