Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ IDEA empty constructor/method code style

How to tweak InlliJ IDEA 14 code style for Java, to make it keep closing brace of empty constructor/method right after opening one.

E. g. :

class A {
    private A() {}
    public void b() {}
}
like image 931
Timofey Gorshkov Avatar asked Nov 12 '14 15:11

Timofey Gorshkov


2 Answers

Go to Settings/Code style/Java/Wrapping and Braces and select these options:

  • Keep when reformatting
    • Simple blocks in one line
    • Simple methods in one line
    • Simple classes in one line

That will keep code like this untouched while reformatting your code:

if(true) {}
public void foo() {}
public class Bar {}

I tested this on IntelliJ 13.1.5, but hopefully it will work the same way on 14 too.

like image 119
Bohuslav Burghardt Avatar answered Oct 20 '22 21:10

Bohuslav Burghardt


Isn't this the default behaviour of IntelliJ 14? At least in my version it is. As soon as I open curly bracket it gets closed automatically on the same line.

like image 41
user3240544 Avatar answered Oct 20 '22 21:10

user3240544