Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Config IntelliJ switch case style

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?

like image 406
slashms Avatar asked Nov 30 '16 12:11

slashms


People also ask

How can I beautify Java code in IntelliJ?

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 ).

How do I enable auto format in IntelliJ?

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).

How do I fix indentation in IntelliJ?

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.


1 Answers

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

like image 109
Jesper Avatar answered Sep 21 '22 19:09

Jesper