mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
java sealed types: completion for sealed/non-sealed/permits keywords
GitOrigin-RevId: f689d6f04cd86947ce084f9a0b0f1787f81cf694
This commit is contained in:
committed by
intellij-monorepo-bot
parent
38766600e6
commit
a4146e3008
@@ -602,6 +602,9 @@ public class JavaKeywordCompletion {
|
||||
if (!psiClass.isInterface()) {
|
||||
addKeyword(new OverridableSpace(createKeyword(PsiKeyword.IMPLEMENTS), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
if (psiClass.hasModifierProperty(PsiModifier.SEALED)) {
|
||||
addKeyword(new OverridableSpace(createKeyword(PsiKeyword.PERMITS), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.filters.FilterPositionUtil;
|
||||
import com.intellij.psi.impl.source.jsp.jspJava.JspClassLevelDeclarationStatement;
|
||||
@@ -20,6 +21,13 @@ public class ModifierChooser {
|
||||
{PsiKeyword.PUBLIC},
|
||||
{PsiKeyword.FINAL, PsiKeyword.ABSTRACT}
|
||||
};
|
||||
|
||||
private static final String[][] CLASS_15_MODIFIERS = {
|
||||
{PsiKeyword.PUBLIC},
|
||||
{PsiKeyword.FINAL, PsiKeyword.ABSTRACT},
|
||||
{PsiKeyword.FINAL, PsiKeyword.SEALED, PsiKeyword.NON_SEALED}
|
||||
};
|
||||
|
||||
private static final String[][] CLASS_MEMBER_MODIFIERS = {
|
||||
{PsiKeyword.PUBLIC, PsiKeyword.PROTECTED, PsiKeyword.PRIVATE},
|
||||
{PsiKeyword.STATIC},
|
||||
@@ -57,7 +65,7 @@ public class ModifierChooser {
|
||||
PsiElement scope = position.getParent();
|
||||
while (scope != null) {
|
||||
if (scope instanceof PsiJavaFile) {
|
||||
return addClassModifiers(list);
|
||||
return addClassModifiers(list, scope);
|
||||
}
|
||||
if (scope instanceof PsiClass) {
|
||||
return addMemberModifiers(list, ((PsiClass)scope).isInterface(), scope);
|
||||
@@ -69,8 +77,8 @@ public class ModifierChooser {
|
||||
return ArrayUtilRt.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
|
||||
public static String[] addClassModifiers(PsiModifierList list) {
|
||||
return addKeywords(list, CLASS_MODIFIERS);
|
||||
public static String[] addClassModifiers(PsiModifierList list, @NotNull PsiElement scope) {
|
||||
return addKeywords(list, PsiUtil.getLanguageLevel(scope).isAtLeast(LanguageLevel.JDK_15_PREVIEW) ? CLASS_15_MODIFIERS : CLASS_MODIFIERS);
|
||||
}
|
||||
|
||||
public static String[] addMemberModifiers(PsiModifierList list, final boolean inInterface, @NotNull PsiElement position) {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
sealed class Foo <caret>{}
|
||||
@@ -0,0 +1 @@
|
||||
<caret> class Foo {}
|
||||
+2
@@ -186,6 +186,8 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
|
||||
public void testQualifiedNew() { doTest(1, "new"); }
|
||||
public void testRecord() {setLanguageLevel(LanguageLevel.JDK_14_PREVIEW); doTest(); }
|
||||
public void testRecordInFileScope() {setLanguageLevel(LanguageLevel.JDK_14_PREVIEW); doTest(1, "record"); }
|
||||
public void testSealedModifier() {setLanguageLevel(LanguageLevel.JDK_15_PREVIEW); doTest(1, "sealed"); }
|
||||
public void testPermitsList() {setLanguageLevel(LanguageLevel.JDK_15_PREVIEW); doTest(1, "permits"); }
|
||||
|
||||
public void testOverwriteCatch() {
|
||||
configureByTestName();
|
||||
|
||||
Reference in New Issue
Block a user