Intention “Sort Content” not availlable on some enum files in IntelliJ IDEA

Answered

IntelliJ has an Intention to sort the members of an enum alphabetically, we use this to avoid merge conflicts when adding new members to the enum.

This works for the majority of our enum files, but doesn't seem availlable for a couple of enums.

I know the intention doesn't show up when the members are already sorted, but this isn't the case.

Is there another condition for this intention to show up ?

I am using IntelliJ IDEA 2020.1.1

 

UPDATE: it seems that when the name of EVERY member in the enum is changed (by adding temporary suffix with find and replace) the Sort Intention becomes availlable, this is a workaround, but nog a solution on the long term.

0
5 comments

There are no reported bugs regarding "Sort Content" and enums.

Can you show the code sample where the intention is not working, so I can reproduce the case? 

 

0
Avatar
Permanently deleted user

Hello, I can show code sample:

public enum A {
// alt + enter -> sort content available

ELEM_1,
ELEM_3,
ELEM_2;
}
public enum B {
// alt + enter -> sort content unavailable

ELEM_1(A.ELEM_1),
ELEM_3(A.ELEM_3),
ELEM_2(A.ELEM_2);

private final A a;

B(A a) {
this.a = a;
}

public A getA() {
return a;
}
}

IntelliJ IDEA 2020.1.1 (Community Edition)
Build #IC-201.7223.91, built on April 30, 2020
Runtime version: 11.0.6+8-b765.40 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 974M
Cores: 4
Non-Bundled Plugins: com.jetbrains.edu

0

Created bug request for you. Feel free to follow for updates: https://youtrack.jetbrains.com/issue/IDEA-243027

0
Avatar
Permanently deleted user

Sort content available for enums with constructor:

public enum C {
// alt + enter -> sort content available

ELEM_1("ELEM_1"),
ELEM_3("ELEM_3"),
ELEM_2("ELEM_2");

private final String str;

C(String str) {
this.str = str;
}

public String getStr() {
return str;
}
}

Sorting is not available when using enum elements in a constructor.

0

Thanks, edited. 

Feel free to write directly into YouTrack item in the future. 

0

Please sign in to leave a comment.