[java] fix strange completion when trying to create vararg parameter (IDEA-346732)

GitOrigin-RevId: 7ba3612b1df542111163d635ae1fdd0ad8877fce
This commit is contained in:
Bas Leijdekkers
2024-02-22 18:38:34 +00:00
committed by intellij-monorepo-bot
parent a5fe427fb0
commit 8c84138f29
6 changed files with 22 additions and 3 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInsight.completion;
import com.intellij.application.options.CodeStyle;
@@ -88,7 +88,10 @@ public final class JavaCompletionContributor extends CompletionContributor imple
psiElement().afterLeaf(".").insideStarting(psiExpressionStatement()),
// like `call(Cls::methodRef.<caret>`
psiElement().afterLeaf(psiElement(JavaTokenType.DOT).afterSibling(psiElement(PsiMethodCallExpression.class).withLastChild(
psiElement(PsiExpressionList.class).withLastChild(psiElement(PsiErrorElement.class))))));
psiElement(PsiExpressionList.class).withLastChild(psiElement(PsiErrorElement.class))))),
// dot after primitive type `int.<caret>` or dot after dot `Object..<caret>`
psiElement().afterLeaf(psiElement(JavaTokenType.DOT).withParent(
psiElement(PsiErrorElement.class).afterSibling(psiElement(PsiErrorElement.class)))));
private static final PsiNameValuePairPattern NAME_VALUE_PAIR =
psiNameValuePair().withSuperParent(2, psiElement(PsiAnnotation.class));
private static final ElementPattern<PsiElement> ANNOTATION_ATTRIBUTE_NAME =
@@ -0,0 +1,3 @@
public class Foo {
void foo(int.<caret>){ }
}
@@ -0,0 +1,3 @@
public class Foo {
void foo(int..<caret>){ }
}
@@ -0,0 +1,3 @@
public class Foo {
void foo(int...<caret>){ }
}
@@ -0,0 +1,3 @@
public class Foo {
void foo(int..<caret>){ }
}
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.java.codeInsight.completion;
import com.intellij.application.options.CodeStyle;
@@ -1127,6 +1127,10 @@ public class NormalCompletionTest extends NormalCompletionTestCase {
public void testEnumConstantFromEnumMember() { doTest(); }
public void testPrimitiveMethodParameter() { doTest(); }
public void testPrimitiveVarargMethodParameter() { doTest("."); }
public void testPrimitiveVarargMethodParameter2() { doTest("."); }
public void testNewExpectedClassParens() { doTest("\n"); }