Customize the Eclipse Outline

What’s your first action after opening an unknown class file with the Eclipse IDE? I for myself first inspect the Outline view to get a general idea about the involved members and methods. It’s totally crucial to me to optimize the contents of the Outline view, thus minimizing the time to getting started with unknown sourcecode. Let’s take a look how to improve the Outline view.

Modifying the Outlines structure

First thing to change is the Outlines structure. Per default the Outline view shows (i) the files package, (ii) import declarations and (iii) the files members and methods. I’m only interested in point (iii) so the first thing to do is hiding the package and import declarations. Click on the little arrow button in the Outlines toolbar, then click Go Into Top Level Type.

Sorting the Outlines contents

I prefer a well-defined ordering of the class files members and methods. Toggle the sort button in the Outlines toolbar to order the contents alphabetically. Additionally Eclipse enables you to get visibilities involved into the sorting. At the preferences dialog, go to Java -> Appearance -> Members Sort Order then check Sort members in same category by visibility. You can also change the sequence here to fit your needs.

Filtering the Outlines contents

Eclipse enables you to filter the Outlines members in different ways. The Outlines toolbar contains toggle buttons to show/hide fields, static fields and members and local types. I prefer to hide local types (e.g. anonymous implementations) the whole time while showing or hiding fields and static members depending on the situation. It’s also possible to filter contents by pattern. In the Outlines toolbar click on the arrow button, then choose Filters. In the dialog activate Name Filter Patterns then insert the desired pattern into the textfield.

Categorizing the Outlines contents

One of the most demanded feature is to hide getters and setters in Java files. This is possible in the Outline view by using the categories feature. For each type, member and method you can define a category directly from the sourcecode via the Javadoc keyword @category followed by one or many category names (e.g. getter or setter). The Outline view automatically shows the names of the categories on any element. Besides you can filter the Outlines contents by categories, just click on the arrow button in the Outlines toolbar and click on a category to show or hide. If you like this feature I recommend you to modify the javadoc code templates for getters and setters. In the preferences dialog go to Java -> Code Style -> Code Templates, then edit the values for comments for getter function and comments for setter function. Add @category getter and @category setter respectively. Hence Eclipse will generate the appropriate categories automatically while auto-generating getters and setters.

Read More