mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
SortContentAction: limit intention in enums only to declaration of enum
This commit is contained in:
@@ -807,6 +807,9 @@ public class SortContentAction extends PsiElementBaseIntentionAction {
|
||||
if (!aClass.isEnum()) return null;
|
||||
PsiEnumConstant[] constants = PsiTreeUtil.getChildrenOfType(aClass, PsiEnumConstant.class);
|
||||
if (constants == null || constants.length < MIN_ELEMENTS_COUNT) return null;
|
||||
PsiEnumConstant last = constants[constants.length - 1];
|
||||
PsiElement lastEnumRelatedElement = getLastEnumDeclarationRelatedElement(last);
|
||||
if (lastEnumRelatedElement.getTextRange().getEndOffset() <= origin.getTextOffset()) return null;
|
||||
PsiElement lBrace = aClass.getLBrace();
|
||||
if (lBrace == null) return null;
|
||||
PsiElement nextAfterLbrace = lBrace.getNextSibling();
|
||||
@@ -814,6 +817,17 @@ public class SortContentAction extends PsiElementBaseIntentionAction {
|
||||
return new EnumContext(Arrays.asList(constants), nextAfterLbrace);
|
||||
}
|
||||
|
||||
private static @NotNull PsiElement getLastEnumDeclarationRelatedElement(@NotNull PsiEnumConstant last) {
|
||||
PsiElement current = last.getNextSibling();
|
||||
while (current instanceof PsiWhiteSpace
|
||||
|| current instanceof PsiComment
|
||||
|| (current instanceof PsiJavaToken && (((PsiJavaToken)current).getTokenType() == JavaTokenType.COMMA))
|
||||
) {
|
||||
current = current.getNextSibling();
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
List<PsiElement> getElements(@NotNull EnumContext context) {
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Sort content" "false"
|
||||
|
||||
enum e {
|
||||
Foo,
|
||||
Bar,
|
||||
Baz;
|
||||
<caret>
|
||||
}
|
||||
Reference in New Issue
Block a user