Homepage/ blog/ 2015/ 07/ Java formatter for Eclipse Mars

I normally use eclipse and for me is a good IDE.

Eclipse comes with a built-in Java formatter that is not compliance with the Java convention and for this reason I create a Java formatter available on github, click here to get the latest version.

In short my 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

The following instructions and the formatter are tested for Eclipse Mars (version 4.5).


Instructions:

  1. Clone git repository or download the Java formatter

  2. Start eclipse

  3. Click on Window → Preferences
    Eclipse Window --> Preferences

  4. Search "formatter" in filter text input bar and then select Java → Code Style → Formatter
    Eclipse Java --> Code Style --> Formatter

  5. Click on "Import..." button and select the Java formatter, previously downloaded

  6. Verify that "Java and Google Conventions - pirola.org" is the Active profile and click on "Apply" Eclipse Java --> Code Style --> Formatter --> Apply

  7. Click and "OK"

That's all!!!

You can format your code in different ways:

  • All classes

    1. Click with the right mouse button on src/main/java, if you use maven, or on root project an select "Source" → "Format"
      Eclipse Java --> Source --> Format
  • Single class

    1. Select all your Java code class- Shortcut: Right Ctrl + A
      Eclipse Java --> Right Ctrl + A

    2. Format the code - Shortcut: Right Ctrl + Right Shift + F
      Eclipse Java --> Right Ctrl + Right Shift + F

Happy coding ;)

Comments

No comments yet.

Add Comment

* Required information
What is the sum of 1 + 2 + 3?
 
Enter answer:
 
I have read and understand the privacy policy. *
 
I have read and agree to the terms and conditions. *
 
 
Powered by Commentics