The default Eclipse formatter formats my Java code in a really funny way.
For example: hello.show().x().y()
would oddly be formatted as x()
and .y()
, and be placed on a separate line.
Are there any other basic formatters that can do a better job?
Examples and links are very welcome.
Go to Source | Format Document or press Ctrl+Shift+F.
You can use Ctrl + A to select the entire file, then use this shortcut to quickly fix all the indentation. You can also change how Eclipse handles indentation by going to Window > Preferences, then in the left panel, navigate to Java > Code Style > Formatter > Edit... > Indentation.
I would highly recommend the google's style guide, it's a collection of coding style guide for commonly used programming languages.
The eclipse configurable Java guide can be found here. Installing the guide is quite simple, Save the style xml to a file and import it using the following dialogue box:
Window -> Preferences -> Java -> Code Style -> Formatter
Finally select the active profile as GoogleStyle.
I always change the formatter in Eclipse to Java Convention AND change the tab policy to always use space instead of tab or mixing of tab and space. Sometime I change also the line width to be 100 or 120 (80 characters is just too narrow in my monitor).
Regarding your specific request: yes you can change this behavior. Go to the Formatter preference and create your own profile. Modify it on tab Line Wrapping and uncheck Prefer wrapping outer expressions (keep nested expression on one line)
.
More information on: https://bugs.eclipse.org/bugs/show_bug.cgi?id=313524
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With