Sort enum properties

I am creating an enum and adding fields afterwards. I'd like to see those fields within the enum sorted alphabetically, which is why I am adding the fields in alphabetic order. However, after having called PsiClass::add, the properties are not in order any more.
How can I sort properties on a class, especially on an enum?

Some code:
PsiClass propertyEnum = psiElementFactory.createEnum(PROPERTY_ENUM_NAME);
.map(f -> f.getElement().getName())
.filter(n -> n != null)
.map(n -> psiElementFactory.createEnumConstantFromText(n, contextClass))

Please sign in to leave a comment.