wiki:ConfiguringIDE

Version 12 (modified by Rene Ranzinger, 7 years ago) (diff)

--

Configuring the Eclipse IDE

Why change the Eclipse configuration?

By the default Eclipse IDE is configured in a way to make the majority of developers happy. However that may not fit your needs or your taste. By changing some the IDE settings you may be able to use Eclipse more efficiently and produce better code.

Please note : All settings on this page are recommendations and show my personal preferences. If something does not work for you or you disagree with it please feel free to ignore the corresponding chapters. After all your settings are as right and wrong as mine are.

Settings for Text Editors

The following settings apply to all text editors include Java and XML editors. To change these settings open the IDE preferences and go to General > Editors > Text Editors:

  • Insert spaces for tabs will replace tabs with spaces and avoid mix of tabs and spaces which can result in misalignment in some systems. The number of spaces for each tab is specified in Displayed tab width. Keep in mind for Java Editors there is a separate setting for this.
  • Show line numbers will display the line number on the left side of the text editor. This helps when searching for bugs based on exception stacktraces or when talking with colleagues about the code.
  • Show whitespace characters similar to Word this will show spaces, tabs and returns. This is sometimes useful when lines are much indented or non-ASCII characters. The link configure visibility lets you choose which characters to show and also the transparency level.

Typing in Java

The following settings can be found in the preferences in Java > Editor > Typing.

  • An often occurring problem is as missing semicolon or brace in a code line. Enabling the Automatically insert at correct position option will add the semicolon or brace at the right place in the line independent where you type.
  • Escape text when pasting into a string literal will automatically escape all special characters when a text (e.g. HTML or XML) is pasted into a string (e.g. String a = "" => paste between ").

Highlighting of brackets

It is useful to see where the current code block starts and ends. In the Eclipse preference under Java > Editor you can change the Bracket highlighting to Eclosing brackets. Now the enclosing () or {} will be highlighted when placing the cursor.

Link the editors with the Package Explorer view

Sometimes it is hard to find out where the file you have opened in an editor is physically located (e.g. which project, which package, which folder). Linking editors and Package Explorer make sure that the file from the current active editor is always selected in the Package Explorer. To enable or disable this feature click the link button in the Package Explorer:

Save Actions

Eclipse IDE has the option to cleanup your Java code when saving a file. The settings can be found in the preferences on the page Java > Editor > Save Actions.

  • Tick Perform the selected actions on save to enable this feature.
  • Format source code will apply the configured code formatting to the current file. Format all lines may take longer but will fix the entire file.
  • Organize Imports will remove all unused imports from the file and minimize the number of warnings
  • Additional actions can be defined using the Configure button on the right. There are some reasonable defaults already set the following can be added:
    • Remove unnecessary casts
    • Remove trailing white spaces on all lines
    • Correct indentation

Type filter

When using SWT or JFace controls it often happens that Eclipse can not automatically fix the imports since it does not know if java.awt.Button or org.eclipse.swt.widgets.Button is the right import. If you are not working with AWT or SWING in the workspace it is a good idea to filter their classes out, so that only SWT imports are left. This can be configured in the preferences on the page Java > Appearance > Type Filters:

  • Add will allow to add a filter using wildcards (e.g. *,?). The Browse button in the add dialog can help finding the right packages.
  • Remove will remove the selected filter from the configuration.

Autocompletion configuration

When writing a method in Java autocompletion can be used to complete the method. But sometimes the start is not right and instead of x.something you write x.anything. When you go back to the dot and trigger the autocompletion (CTRL+Space in Windows) you can now select the right method but will end up with x.somethinganything or x.something()anything because Eclipse inserted the method rather than overwrite. When using autocompletion Java will by default add the names of the method arguments as placeholders to be replaced with the right variables. However it is also possible to let Eclipse guess the best option and autofill the arguments with the corresponding variables. If that happens often you want to change this behavior in preferences on page Java > Editor > Content Assist:

  • Completion overwrites will fix the mentioned behavior.
  • Insert best guessed arguments in Fill method arguments and show guessed arguments will configure Eclipse to try guessing the right variable based on the current context.

Please Note : The guessing of the parameters does not free you from careful checking that the arguments are correct. Even if Eclipse gets it right in 90+ % of all cases.

Hungarian notation and this.

If you prefer a certain prefix or suffix scheme for naming your variable you can configure this in the preferences on page Java > Code Style. You can also configure Eclipse to use the this. qualifier when generating code involving member variables:

  • Conventions for variable names tables allows to customize prefix and suffix for variables
  • Qualify all generated field accesses with this. will enable the usage of this. in auto-generated code.

Show Breadcrumb

Another way to keep track of the location of the current file is to enable the breadcrumb feature on top of the Java editor. To enable right click in the Java editor (any file) and select Show in Breadcrumb. Any Java editor will have this feature now. To disable it right click on a breadcrumb and choose Hide Breadcrumb.

Package presentation

By default Eclipse will present each Java package in the Package Explorer as an entry under src with its full package name. If the package hierarchy is very deep this can become confusing and space consuming. In this case it may be helpful to present the packages as a tree rather than a list. The following image illustrate the difference:

To switch between the two display options select the menu of the Package Explorer (represented as a little triangle left of the minimize button), choose Package presentation and select either Flat or Hierarchical according to your preference.

Working sets

If an application consists of multiple projects that are present in the workspace it is easily overwhelming and hard to keep track of the current working environment. Eclipse working sets allow to hide certain elements from the Package Explorer reducing the visible elements to a desired set of projects. This is useful if you are working on a single or a few projects right now. Since the other projects are not deleted but just hidden they can still be used for compiling and deploying but will not crowd up the Package Explorer.

Creating a Working set

  • To create a working set select the menu of the Package Explorer (represented as a little triangle left of the minimize button) and choose Select Working Set...

  • In the Select Working Set dialog choose New ....

  • Select Java in the following dialog before clicking on Next

  • Give the working set a name and choose the projects that you want to be visiable by adding them to the Working set content: on the right side before clicking on Finish

Changing the working set

  • To switch between the working sets open the menu of the Package Explorer (represented as a little triangle left of the minimize button) and choose Select Working Set...

  • In the dialog choose Selected Working Sets from the Radio button group and select the working set that you want to see in the list below before pressing OK

  • Now only the projects from the working set are visible.

By choosing No Working Sets in the Select Working Set dialog all projects will be visible again. The same effect can be archived by using the Deselect Working Set entry in the Package Explorer Menu. A list of the recently used working sets will also be directly visible in the Package Explorer menu allowing to quickly switch between the different sets.

Attachments (19)

Download all attachments as: .zip