From 2a18b3e8f9b5c0c6b2abc29c9a5060826149dd45 Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Thu, 3 Dec 2020 17:27:55 +0700 Subject: [PATCH] [java] IDEA-255890 'Complete Current Statement' for vararg method like String.format works incorrectly GitOrigin-RevId: 814641fd0562890897eec6e0a7f29c187f36c54c --- .../editorActions/smartEnter/MethodCallFixer.java | 2 +- .../codeInsight/completeStatement/VarargMethod.java | 6 ++++++ .../codeInsight/completeStatement/VarargMethod_after.java | 6 ++++++ .../intellij/java/codeInsight/CompleteStatementTest.java | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/completeStatement/VarargMethod.java create mode 100644 java/java-tests/testData/codeInsight/completeStatement/VarargMethod_after.java diff --git a/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/MethodCallFixer.java b/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/MethodCallFixer.java index 62a62efbd6dd..417d21d39aba 100644 --- a/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/MethodCallFixer.java +++ b/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/MethodCallFixer.java @@ -93,7 +93,7 @@ public class MethodCallFixer implements Fixer { int paramCount = Integer.MAX_VALUE; for (CandidateInfo candidate : PsiResolveHelper.SERVICE.getInstance(call.getProject()).getReferencedMethodCandidates(call, false)) { PsiElement element = candidate.getElement(); - if (element instanceof PsiMethod) { + if (element instanceof PsiMethod && !((PsiMethod)element).isVarArgs()) { paramCount = Math.min(paramCount, ((PsiMethod)element).getParameterList().getParametersCount()); } } diff --git a/java/java-tests/testData/codeInsight/completeStatement/VarargMethod.java b/java/java-tests/testData/codeInsight/completeStatement/VarargMethod.java new file mode 100644 index 000000000000..1f40a149e039 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completeStatement/VarargMethod.java @@ -0,0 +1,6 @@ +public class VarargMethod { + void test() { + List list = new ArrayList<>(); + list.add(String.format("m", p1, p2) + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completeStatement/VarargMethod_after.java b/java/java-tests/testData/codeInsight/completeStatement/VarargMethod_after.java new file mode 100644 index 000000000000..1bdb4593e423 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completeStatement/VarargMethod_after.java @@ -0,0 +1,6 @@ +public class VarargMethod { + void test() { + List list = new ArrayList<>(); + list.add(String.format("m", p1, p2)); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/CompleteStatementTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/CompleteStatementTest.java index 58f35794be88..1df53e31c617 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/CompleteStatementTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/CompleteStatementTest.java @@ -181,6 +181,7 @@ public class CompleteStatementTest extends EditorActionTestCase { public void testRecord() { doTest(); } public void testRecordWithComponent() { doTest(); } public void testRecordWithComponentNoBody() { doTest(); } + public void testVarargMethod() { doTest(); } private void doTestBracesNextLineStyle() { myJavaSettings.BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;