Automatically indent align enum parameters in columns (table-like) in IntelliJ

Viewed 128

Say I have an enum like this:

public enum TestEnum {
    TEST1(5, 6, 18, 9, 3),
    TEST2(10, 21, 4, 5, 34),
    TEST3(4, 5, 8, 2, 16),
    TEST4(3, 1, 92, 67, 22);

    TestEnum(int i1, int i2, int i3, int i4, int i5) {
    }
}

How can I automatically (or by clicking Ctrl+Alt+L) format the enum like this:

public enum TestEnum {
    TEST1   (5,     6,      18,     9,      3),
    TEST2   (10,    21,     4,      5,      34),
    TEST3   (4,     5,      8,      2,      16),
    TEST4   (3,     1,      92,     67,     22);
    
    TestEnum(int i1, int i2, int i3, int i4, int i5) {
    }
}

It should optimally use tabs, so that the columns start at indexes divisible by 4 (0, 4, 8, 12 ...)


I tried these workarounds:

  • Formatting myself using @formatter:off, which is
    • a lot of work
    • disables all kinds of formatting like lambda arguments and double spaces

I tried these settings:

  • This setting, which did not do anything:

Settings/Editor/Code Style/Detect and use existing file indents for editing

  • This setting, which only works for fields, variables, assignments and simple methods. It doesn't seem to exist for Kotlin:

Settings/Editor/Code Style/Java/Wrapping and Braces/Group declarations

I tried these plugins:

  • Vertical Align goes into the right direction, but doesn't solve the problem either. It still isn't automatic and doesn't work together with code formatting at all: When pressing Ctrl+Alt+L, the code goes back to normal

  • Same thing for Smart Align, and commas are also being aligned, which looks very weird

  • [Edit] Same thing for Column Align. It is glitched, but doesn't have any other compatibility issues (works in Kotlin, Android Studio and with enums)

  • Tabifier is old and thus doesn't work on Android

  • Java Code Aligner neither works for Kotlin nor enums

Edit:

As suggested by quickfix, I added a YouTrack suggestion.

0 Answers
Related