4.4. Eclipse Code Style

Eclipse provides a number of interrelated features to help write code consistent with defined standards.

4.4.1. Formatter

The Eclipse formatter config file (accessible here) defines a set of formatting standards consistent with the Checkstyle checks (see Section 4.1, “Checkstyle”). The config file should be imported using Windows > Preferences > Java > Code Style > Formatter:

To run the formatter, use Source > Format. Alternatively, you can use Cleanup, below, which performs formatting and a number of other checks too.

4.4.2. Cleanup

The Eclipse cleanup config file (accessible here) defines a set of operations aimed at removing simple problems with the code, again consistent with the Checkstyle checks (see Section 4.1, “Checkstyle”). These include running the formatter, above. The config file should be imported using Windows > Preferences > Java > Code Style > Cleanup:

The cleanup wizard can be run on an adhoc basis using Source > Cleanup.

4.4.3. Save Actions

While the formatter and cleanup can be run manually, it is also possible to run the formatter whenever code is saved.

Navigate to Windows > Preferences > Save > Actions and enable:

From the dialog it is also possible to automatically perform the same actions as the cleanup (the Configure button). However, it doesn't seem possible to reuse the configuration definition file. To avoid violating the DRY principle, so the recommendation is just to enable the simple formatting on save and not waste time manually configuring cleanup actions on save too.