New method completion should add newline after closing brace

Answered

This is related to https://intellij-support.jetbrains.com/hc/en-us/community/posts/360010011640-Indent-line-comments-add-line-space-after-starting-new-method.

Even if I set min blank lines around method to 1, if I'm between two methods:

public void m1() {}
<-- cursor at beginning of this blank line
public void m2() {}

I hit Enter and type "public void x() {" and hit Enter again, I'm now here:

public void m1() {}

public void x() {
<-- cursor here, but no blank line after closing brace
}
public void m2() {}

There's no blank line after x(), so I have to manually insert it.

How can I get IntelliJ to automatically add that newline so it looks like this:

public void m1() {}

public void x() {
<-- cursor here, ready to implement
}

public void m2() {}
0
5 comments

Is the blank line inserted when you invoke "Reformat file" action? 

 

0

Yes but I don't want to reformat the whole file, that introduces unnecessary diffs that make code reviews more confusing, and eliminates the occasionally necessary hand-crafted formatting for unique cases.

I just looked at the keymap, I guess I can do Option-Cmd-Return to add a new line below current before I start typing the new method, but it'd be nice if IntelliJ could just handle this. Is there a "new method" template I can modify to add a newline at the end?

0

You can use "Only changes uncommited to VCS" option for reformating: https://i.imgur.com/WvWMXnW.png

 

0

I could, but why should I go through all that extra work of more key presses and a dialog? Can't IntelliJ just follow my "blank lines around method" automatically when it completes the method stub for me?

0

Here is the usability problem in IntelliJ IDEA bug tracker: https://youtrack.jetbrains.com/issue/IDEA-286306

Feel free to follow.

For the time being,  the only option is to reformat manually.

0

Please sign in to leave a comment.