Search code examples
intellij-idea

IntelliJ IDEA one-line function formatting


IntelliJ keeps formatting this:

public void addElement(Element elem) {
    this.elements.add(elem);
}

into this:

public void addElement(Element elem) { this.elements.add(elem); }

I prefer the multi-line formatting. How can I tell this to IntelliJ? I have unchecked the following boxes in Settings -> Editor -> Java -> Wrapping and Braces

  • Control statements in one line
  • Simple blocks in one line
  • Simple methods in one line

Didn't help.


Solution

  • I suspect that your IntelliJ is not actually changing the actual file, but instead, visually collapsing one line methods in the display.

    To have IntelliJ not change the display of one line methods, look at:

    Preferences (or Settings), Editor, General, Code Folding, Collapse by default, One-line methods

    enter image description here