This article shows how to use the Google Java style guide with Eclipse IDE. The benefit of doing this is that it will be easier for you to adhere to your organisation’s style guide by automatically highlighting deviations from it as you write code.
The definition is here.
- Opening Eclipse settings varies per OS. For example, on macOS open Eclipse -> Preferences.
- In the search bar on the left, type “formatter”, and select the Java -> Code Style -> Formatter menu item.
- Click “Import” and browse to the XML file you downloaded in Step 1.
- Ensure the “GoogleStyle” item is selected in the “Active profile” section.
- Click “OK”.
This is a game-changer!
- In the Preferences menu (same as in Step 2), type “save actions”, and select Java -> Editor -> Save Actions.
- Select “Perform the selected actions on save”.
- Select “Format source code”.
- Click the “Formatter” link and ensure the “GoogleStyle” formatter is selected as active.
- Click OK.
Now, whenever you make changes to your code, you can use the format source code menu item, or just save the file and formatting will be applied automatically.