Search code examples
eclipseeclipse-formatter

eclipse formatting new lines at each method property


How can I set up eclipse formatter, to format a method-body to this:

// I want to have a new line on each method property:
public void test(
    double a, 
    double b, 
    String c, 
    Object f
) {
    a = 4;
    b= 3;
    c = "hello";
    f = null;
}

Solution

  • Create a new Eclipse formatter profile based on the Eclipse [built-in] profile and change the following:

    • In the Line Wrapping tab, choose Method Declarations > Parameters:
      • Set Line wrapping policy to Wrap all elements, every element on a new line
      • Check Force split, even if line is shorter than maximum line width
      • Set Indentaton policy to Indent by one
    • In the Parentheses tab, set Method declaration to Separate lines