mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-completion] NormalCompletionTest: use Java 21; also fix case label completion with colon char
GitOrigin-RevId: 84169987b62cb0a1d8bac137f0044ff89e51a7d9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
dd079774bf
commit
3204f9d239
+21
-10
@@ -769,15 +769,7 @@ public final class JavaCompletionContributor extends CompletionContributor imple
|
||||
}
|
||||
|
||||
boolean inSwitchLabel = IN_SWITCH_LABEL.accepts(position);
|
||||
TailType forcedTail = null;
|
||||
if (!smart) {
|
||||
if (inSwitchLabel) {
|
||||
forcedTail = TailTypes.forSwitchLabel(Objects.requireNonNull(PsiTreeUtil.getParentOfType(position, PsiSwitchBlock.class)));
|
||||
}
|
||||
else if (shouldInsertSemicolon(position)) {
|
||||
forcedTail = TailType.SEMICOLON;
|
||||
}
|
||||
}
|
||||
TailType forcedTail = getTailType(smart, inSwitchLabel, position);
|
||||
|
||||
List<LookupElement> items = new ArrayList<>();
|
||||
if (INSIDE_CONSTRUCTOR.accepts(position) &&
|
||||
@@ -805,7 +797,15 @@ public final class JavaCompletionContributor extends CompletionContributor imple
|
||||
LookupItem<?> item = element.as(LookupItem.CLASS_CONDITION_KEY);
|
||||
|
||||
if (forcedTail != null && !(element instanceof JavaPsiClassReferenceElement)) {
|
||||
element = TailTypeDecorator.withTail(element, forcedTail);
|
||||
element = new TailTypeDecorator<>(element) {
|
||||
@Override
|
||||
protected TailType computeTailType(InsertionContext context) {
|
||||
if (context.getCompletionChar() == ':' && forcedTail == TailTypes.CASE_ARROW) {
|
||||
return TailType.CASE_COLON;
|
||||
}
|
||||
return forcedTail;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (inSwitchLabel && !smart) {
|
||||
@@ -837,6 +837,17 @@ public final class JavaCompletionContributor extends CompletionContributor imple
|
||||
return items;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static TailType getTailType(boolean smart, boolean inSwitchLabel, PsiElement position) {
|
||||
if (!smart && inSwitchLabel) {
|
||||
return TailTypes.forSwitchLabel(Objects.requireNonNull(PsiTreeUtil.getParentOfType(position, PsiSwitchBlock.class)));
|
||||
}
|
||||
if (!smart && shouldInsertSemicolon(position)) {
|
||||
return TailType.SEMICOLON;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Collection<LookupElement> getInnerScopeVariables(CompletionParameters parameters, PsiElement position) {
|
||||
PsiElement container = BringVariableIntoScopeFix.getContainer(position);
|
||||
if (container == null) return Collections.emptyList();
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ class C {
|
||||
|
||||
public static void main(A a) {
|
||||
switch (a) {
|
||||
case Abc:<caret>
|
||||
case Abc -> <caret>
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ class A extends Base{
|
||||
void foo(){
|
||||
B x = null;
|
||||
switch(x){
|
||||
case GOO:<caret>
|
||||
case GOO -> <caret>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
public class Demo {
|
||||
void foo(Integer i){
|
||||
switch(i) {
|
||||
case Types.CHAR:<caret>
|
||||
case Types.CHAR -> <caret>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
-10
@@ -16,16 +16,14 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.impl.NonBlockingReadActionImpl;
|
||||
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.augment.PsiAugmentProvider;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.psi.impl.light.LightMethodBuilder;
|
||||
import com.intellij.psi.impl.source.PsiExtensibleClass;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.NeedsIndex;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.ServiceContainerUtil;
|
||||
import com.intellij.testFramework.*;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.siyeh.ig.style.UnqualifiedFieldAccessInspection;
|
||||
@@ -46,7 +44,7 @@ public class NormalCompletionTest extends NormalCompletionTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_9;
|
||||
return JAVA_21;
|
||||
}
|
||||
|
||||
public void testSimple() throws Exception {
|
||||
@@ -306,7 +304,7 @@ public class NormalCompletionTest extends NormalCompletionTestCase {
|
||||
|
||||
public void testSwitchEnumLabel() {
|
||||
configureByFile("SwitchEnumLabel.java");
|
||||
assertEquals(3, myItems.length);
|
||||
assertEquals("[A, B, C, null]", ContainerUtil.map(myItems, LookupElement::getLookupString).toString());
|
||||
}
|
||||
|
||||
public void testSwitchCaseWithEnumConstant() { doTest(); }
|
||||
@@ -976,7 +974,9 @@ public class NormalCompletionTest extends NormalCompletionTestCase {
|
||||
checkResult();
|
||||
}
|
||||
|
||||
public void testCaseTailType() { doTest(); }
|
||||
public void testCaseTailType() {
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_11, this::doTest);
|
||||
}
|
||||
|
||||
private void doPrimitiveTypeTest() {
|
||||
configure();
|
||||
@@ -992,7 +992,7 @@ public class NormalCompletionTest extends NormalCompletionTestCase {
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void testFinalInForLoop2() {
|
||||
configure();
|
||||
myFixture.assertPreferredCompletionItems(0, "finalize", "final");
|
||||
myFixture.assertPreferredCompletionItems(1, "finalize", "final");
|
||||
}
|
||||
|
||||
public void testOnlyClassesInExtends() {
|
||||
@@ -2263,7 +2263,9 @@ public class NormalCompletionTest extends NormalCompletionTestCase {
|
||||
checkResult();
|
||||
}
|
||||
|
||||
public void testCaseColonAfterStringConstant() { doTest(); }
|
||||
public void testCaseColonAfterStringConstant() {
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_11, this::doTest);
|
||||
}
|
||||
|
||||
public void testOneElementArray() {
|
||||
configureByTestName();
|
||||
@@ -2678,7 +2680,8 @@ public class NormalCompletionTest extends NormalCompletionTestCase {
|
||||
}""");
|
||||
myFixture.completeBasic();
|
||||
assertEquals("return", myFixture.getLookupElements()[0].getLookupString());
|
||||
var element = myFixture.getLookupElements()[1];
|
||||
assertEquals("record", myFixture.getLookupElements()[1].getLookupString());
|
||||
var element = myFixture.getLookupElements()[2];
|
||||
assertEquals("result", element.getLookupString());
|
||||
LookupElementPresentation presentation = renderElement(element);
|
||||
assertEquals(" (from if-then block)", presentation.getTailText());
|
||||
|
||||
Reference in New Issue
Block a user