101

Since I've updated my version of intelliJ (14.x to 15.x) it has started automatically collapsing single line methods in the Java editor:

Previous version:

public void setContext(SecurityContext context) {
    this.context = context;
}

Latest version:

public void setContext(SecurityContext context) { this.context = context; }

Is there a way to prevent this? I find the original version much easier on the eyes!

Thanks.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
StuPointerException
  • 7,117
  • 5
  • 29
  • 54
  • 5
    I don't think it formats this code, it just collapses it. When you look on the left border of the code view, there should be a small "+" sign to expand it, like for the `import` block. – Tom Mar 14 '16 at 18:22
  • 3
    Ah yes, I'll change the wording of the question to reflect this. Thanks! – StuPointerException Mar 14 '16 at 18:26
  • See duplicate: [*IntelliJ IDEA one-line function formatting*](https://stackoverflow.com/q/36294708/642706) – Basil Bourque Oct 06 '18 at 23:09

3 Answers3

153

Open 'Settings' from the File menu. Under 'Editor' -> 'General' -> 'Code Folding', you will find a 'Collapse by Default' section.

Simply uncheck 'One-line methods' and click OK.

enter image description here

Ivan Ivanov
  • 2,076
  • 16
  • 33
rmlan
  • 4,387
  • 2
  • 21
  • 28
  • this will also work if you put an opening brace in new line and want to fold it to `{...}` instead of `latest version` of question – Marek May 05 '17 at 09:54
  • 6
    One thing to note : You'll have to re-open the file for the changes to take effect. – Traxex1909 Nov 02 '17 at 07:05
  • 8
    Update: for newer versions of IJ uncheck: File | Settings | Editor | General | Code Folding | Java | One line methods – Scott Jul 25 '20 at 01:25
10

On Windows:

Settings -> Editor -> General -> Code Folding -> Uncheck "One-line methods"

ToDo
  • 754
  • 2
  • 17
  • 31
2

For mac, Code > Folding > Expand ALL/To Level

Atul Kaushik
  • 5,181
  • 3
  • 29
  • 36