mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Sealed classes: suggest 'sealed' modifier for inner classes (IDEA-249580)
GitOrigin-RevId: 7ea47ec84d6250868ed605e12d169f13ab373b3d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a2c00e3b8f
commit
fa94ad5f5f
@@ -39,6 +39,25 @@ public final class ModifierChooser {
|
||||
{PsiKeyword.TRANSIENT}
|
||||
};
|
||||
|
||||
private static final String[][] CLASS_15_MEMBER_MODIFIERS = {
|
||||
{PsiKeyword.PUBLIC, PsiKeyword.PROTECTED, PsiKeyword.PRIVATE},
|
||||
{PsiKeyword.STATIC},
|
||||
{PsiKeyword.FINAL, PsiKeyword.ABSTRACT},
|
||||
{PsiKeyword.SEALED, PsiKeyword.NON_SEALED},
|
||||
{PsiKeyword.NATIVE},
|
||||
{PsiKeyword.SYNCHRONIZED},
|
||||
{PsiKeyword.STRICTFP},
|
||||
{PsiKeyword.VOLATILE},
|
||||
{PsiKeyword.TRANSIENT}
|
||||
};
|
||||
|
||||
private static final String[][] INTERFACE_15_MEMBER_MODIFIERS = {
|
||||
{PsiKeyword.PUBLIC, PsiKeyword.PROTECTED, PsiKeyword.PRIVATE},
|
||||
{PsiKeyword.STATIC, PsiKeyword.DEFAULT},
|
||||
{PsiKeyword.FINAL, PsiKeyword.ABSTRACT},
|
||||
{PsiKeyword.SEALED, PsiKeyword.NON_SEALED}
|
||||
};
|
||||
|
||||
private static final String[][] INTERFACE_9_MEMBER_MODIFIERS = {
|
||||
{PsiKeyword.PUBLIC, PsiKeyword.PROTECTED, PsiKeyword.PRIVATE},
|
||||
{PsiKeyword.STATIC, PsiKeyword.DEFAULT},
|
||||
@@ -82,10 +101,13 @@ public final class ModifierChooser {
|
||||
}
|
||||
|
||||
public static String[] addMemberModifiers(PsiModifierList list, final boolean inInterface, @NotNull PsiElement position) {
|
||||
return addKeywords(list, inInterface ? getInterfaceMemberModifiers(position) : CLASS_MEMBER_MODIFIERS);
|
||||
return addKeywords(list, inInterface ? getInterfaceMemberModifiers(position) : getClassMemberModifiers(position));
|
||||
}
|
||||
|
||||
private static String[][] getInterfaceMemberModifiers(@NotNull PsiElement list) {
|
||||
if (PsiUtil.getLanguageLevel(list).isAtLeast(LanguageLevel.JDK_15_PREVIEW)) {
|
||||
return INTERFACE_15_MEMBER_MODIFIERS;
|
||||
}
|
||||
if (PsiUtil.isLanguageLevel9OrHigher(list)) {
|
||||
return INTERFACE_9_MEMBER_MODIFIERS;
|
||||
}
|
||||
@@ -95,6 +117,13 @@ public final class ModifierChooser {
|
||||
return INTERFACE_MEMBER_MODIFIERS;
|
||||
}
|
||||
|
||||
private static String[][] getClassMemberModifiers(@NotNull PsiElement list) {
|
||||
if (PsiUtil.getLanguageLevel(list).isAtLeast(LanguageLevel.JDK_15_PREVIEW)) {
|
||||
return CLASS_15_MEMBER_MODIFIERS;
|
||||
}
|
||||
return CLASS_MEMBER_MODIFIERS;
|
||||
}
|
||||
|
||||
private static String[] addKeywords(PsiModifierList list, String[][] keywordSets) {
|
||||
final List<String> ret = new ArrayList<>();
|
||||
for (int i = 0; i < keywordSets.length; i++) {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
<caret> class Bar {}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
interface Foo {
|
||||
private <caret> class Bar {}
|
||||
}
|
||||
+2
@@ -200,6 +200,8 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
|
||||
public void testSealedModifier() {setLanguageLevel(LanguageLevel.JDK_15_PREVIEW); doTest(1, "sealed"); }
|
||||
public void testPermitsList() {setLanguageLevel(LanguageLevel.JDK_15_PREVIEW); doTest(1, "permits"); }
|
||||
public void testEnumPermitsList() {setLanguageLevel(LanguageLevel.JDK_15_PREVIEW); doTest(0, "permits"); }
|
||||
public void testInnerClassSealedModifier() {setLanguageLevel(LanguageLevel.JDK_15_PREVIEW); doTest(1, "sealed");}
|
||||
public void testInterfaceInnerClassSealedModifier() {setLanguageLevel(LanguageLevel.JDK_15_PREVIEW); doTest(1, "sealed");}
|
||||
|
||||
public void testOverwriteCatch() {
|
||||
configureByTestName();
|
||||
|
||||
Reference in New Issue
Block a user