Java formatter for eclipse mars (version 4.5). This formatter is also tested for eclipse Juno (version 3.8.1) and could be imported into IntelliJ IDEA.
In short the Java formatter:
- indent 4 spaces
- use space instead of the tab character
- split every row @ 80 characters per line
- format the Javadoc
- don't format comment
- try to be compliance with the Java and Google conventions
- pass verify of checkstyle
- possible to turn off/on Java formatter with the following strings:
- //CHECKSTYLE:OFF
- //CHECKSTYLE:ON
In "test-project" directory you can find a test project in order to verify the Java formatter.
-
Clone git repository or download the Java formatter
-
Start eclipse
-
Click on Window --> Preferences
-
Search "formatter" in filter text input bar and then select Java --> Code Style --> Formatter
-
Click on "Import..." button and select the Java formatter, previously downloaded
-
Verify that "Java and Google Conventions - pirola.org" is the Active profile and click on "Apply"
-
Click and "OK"
You can format your code in different ways:
-
All classes
- Click with the right mouse button on src/main/java, if you use maven, or on root project an select "Source" --> "Format"
- Click with the right mouse button on src/main/java, if you use maven, or on root project an select "Source" --> "Format"
-
Single class
-
Select all your Java code class - Shortcut: Right Ctrl + A
-
Format the code - Shortcut: Right Ctrl + Right Shift + F
-