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) {}
Go to Settings/Preferences | Editor | Code Style, select your programming language, and open the Wrapping and Braces tab. In the Keep when reformatting section, select the formatting rules which you want to ignore and deselect those which should be applied. Reformat your code ( Ctrl+Alt+L ).
You can use ⌘⌥L (macOS), or Ctrl+Alt+L (Windows/Linux) to reformat a selection of code according to your reformat settings. You can also display the Reformat File dialog with ⌥⇧⌘L (macOS), or Ctrl+Alt+Shift+L (Windows/Linux).
In Preferences > Editor > Code style > [language] uncheck reformat on file save .
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.
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
You can remove the unnecessary line breaks more universally throughout a project than just remove the newline before curly braces.
First go to the following setting and set a larger value for hard wrap:
Settings > Editor > Code Style
The default is 120. Change it to 250 or any other large value.
Next, navigate to the following setting:
Settings > Editor > Code Style > Java > Wrapping and Braces > Keep when reformatting > Line breaks
Uncheck "line breaks"
Finally, go back to your file and try to reformat the code.
This removes all the unnecessary line breaks that have been put into the code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With