IntelliJ, Java formatting: force empty blocks to b

2020-08-09 08:06发布

问题:

Is it possible to tell IntelliJ to put empty block on one line when formatting Java files.

I'd like this:

@Override
public void onClickPositive(int tag, Object payload) {
}

To automatically become this:

@Override
public void onClickPositive(int tag, Object payload) {}

回答1:

There is no way to do it for reformatting code.

This can only be done manually.

Check your Code Style settings, under "Alignment and Braces" to preserve your formatting. You should find a "Simple methods in one line" option there. Check it and clear the "Line breaks" check box.



回答2:

Enable following Simple blocks in one line code style in settings.

Settings > Editor > Code Style > Java > Wrapping and Braces > Keep when reformatting > Simple blocks in one line