Intellij keeps formatting my switch case as follows:
switch (enumVal) {
case X:
//do stuff
break;
case Y:
//do stuff
break;
}
But I would like it to be formatted like Sun style:
switch (enumVal) {
case X:
//do stuff
break;
case Y:
//do stuff
break;
}
Is there a way to config that?
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 ).
Sometimes code formatting can get out of sync, but there's an easy fix in IntelliJ IDEA. 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).
While in the editor, select the necessary code fragment and press Ctrl+Alt+I . If you need to adjust indentation settings, in the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Editor | Code Style. On the appropriate language page, on the Tabs and Indents tab, specify the appropriate indents options and click OK.
Go to Settings > Editor > Code Style > Java, select tab "Wrapping and Braces", scroll down the list to 'switch' statement, uncheck the option "Indent 'case' branches".
More information: IntelliJ 2016.3 Help - Code Style, Java
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