Sort enum properties

Hi,
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?
Thanks,
Matthias

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

Please sign in to leave a comment.