Eclipse formatter settings for the Builder pattern

Turning off formatting with comments, or inserting line comments is too tedious.

The best way is described here:

... or you can select "Line Wrapping > Never join already wrapped lines" globally. Then, you can break it manually and the formatter will only format inside lines (or add additional line breaks if necessary).

With this setting Eclipse formatter will stop ruining your builder statements.

enter image description here


Use comments:

   Object o = foo() //
      .bar() //
      .toString();

Update for 2021. It is possible to change, navigate to: Code Style -> Formatter -> Line Wrapping -> Wrapping settings -> Function Calls -> Qualified invocations and change value to "Wrap all elements, except first element if not necessary"


In Eclipse 3.6 It's possible to turn off formatting for a region of code. See my answer to

How to turn off the Eclipse code formatter for certain sections of Java code?


AFAIK, this is known problem with Eclipse Formatter: https://bugs.eclipse.org/bugs/show_bug.cgi?id=59891