views:

120

answers:

3

The default eclipse formatter formats my java code really funny.

For example: hello.show().x().y() would be formatted oddly. .x() and .y() would be placed on a seperate line.

Are there any other basic formatters that can do a better job?

Examples and links welcome.

+4  A: 

Have you considered looking at the preferences for the formatter? You can basically configure it to do anything you want.

I would, however, strongly consider the standard Eclipse formatting. It helps a lot to just use the standard, and then adjust your coding style to work well with that.

Thorbjørn Ravn Andersen
+3  A: 

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

nanda
exactly what i was looking for
Sheehan Alam
A: 

In addition to the ability to customize the formatter, as indicated by Thorbjørn, it is also possible to import coding conventions from specific projects, especially the ones from frameworks and libraries that you are working on.

For instance, the Spring framework coding conventions have been made available, as is the case with Android. Eventually, you're better off starting with the Sun coding conventions (than a completely hand-crafted one), with a few tweaks done to suit your organization's coding style and readability requirements.

Vineet Reynolds