1

I use the Eclipse formatter with the option on save enabled.

Right now code like this:

 int sum = widgets.stream()
                  .filter(b -> b.getColor() == RED)
                  .mapToInt(b -> b.getWeight())
                  .sum();

will be formatted to:

 int sum = widgets.stream().filter(b -> b.getColor() == RED).mapToInt(b -> b.getWeight())
                  .sum();

is there a setting which will do automated linebreak for everything but cascading function calls?

gerripeach
  • 13
  • 3
  • I think this may be answered here: [https://stackoverflow.com/questions/5199255/how-to-disable-auto-formatting-upon-save-in-eclipse](https://stackoverflow.com/questions/5199255/how-to-disable-auto-formatting-upon-save-in-eclipse) – DevilCode Feb 21 '20 at 20:21

1 Answers1

0

Steps to format cascading function calls:

1. Window => Preferences => Java => Code Style => Formatter

2. Click Edit.

3. Expand Line Wrapping => Wrapping Settings => Function Calls

4. Change Qualified invocations to Wrap all elements, except first element if not necessary.

  • Additionally, ensure Force split, even if line shorter than maximum line width is toggled on.

See image below for what it looks like when set correctly:

Qualified Invocation Location

5. Change Profile Name if necessary.

6. Apply and close.

Nexevis
  • 4,647
  • 3
  • 13
  • 22