Search code examples
javaeclipseformatting

Put each statement in if-clause on new line in Eclipse


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();
}

Solution

  • 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.