Home > Software engineering >  Put each statement in if-clause on new line in Eclipse
Put each statement in if-clause on new line in Eclipse

Time:04-30

In Eclipse formatter for Java how can I format if-statements like

if (x != null
    && x.getSomething() != null
    && x.getSomething().getSomethingMore()) {
  y.doSomething();
}

if they exceed the max line width (each statement on new line!). I thought it should be done with

enter image description here

but somehow I am wrong. Result:

if (x != null && x.getSomething() != null
    && x.getSomething().getSomethingMore()) {
 y.doSomething();
}

CodePudding user response:

I'd recommend you to select the following options:

- Wrap all elements, every element on a new line

I do:

- Wrap before operators
- Wrap all elements, every element on a new line
- Force split
- Indent by one

Screenshot:

enter image description here

I hope this help you.

  • Related