parameter info: process vararg call to select appropriate overload (IDEA-229623)

GitOrigin-RevId: baccfda899c6ae8dbd3b5506ef6f29c960cf79bd
This commit is contained in:
Anna Kozlova
2021-07-15 14:03:32 +02:00
committed by intellij-monorepo-bot
parent aa40e9cd04
commit 241b7042d4
3 changed files with 23 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 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.
// Copyright 2000-2021 JetBrains s.r.o. and contributors. 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.hint.api.impls;
import com.intellij.codeInsight.AnnotationTargetUtil;
@@ -364,9 +364,12 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
chosenInfo = candidate;
}
if (parms.length == args.length && realResolve == method &&
isAssignableParametersBeforeGivenIndex(parms, args, args.length, substitutor)) {
completeMatch = candidate;
if (realResolve == method) {
if (parms.length == args.length && isAssignableParametersBeforeGivenIndex(parms, args, args.length, substitutor) ||
method.isVarArgs() && parms.length - 1 <= args.length &&
isAssignableParametersBeforeGivenIndex(parms, args, Math.min(parms.length, args.length), substitutor)) {
completeMatch = candidate;
}
}
}
}

View File

@@ -0,0 +1,9 @@
class Main {
void f(Throwable t){
main("", <caret>t);
}
public static void main(String s, Throwable t, String... args) { }
public static void main(String s, String... args) { }
}

View File

@@ -1,4 +1,4 @@
// 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.
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.codeInsight;
import com.intellij.JavaTestUtil;
@@ -108,6 +108,10 @@ public class ParameterInfoTest extends AbstractParameterInfoTestCase {
public void testOverloadWithVarargsSingleArg() {
doTest2CandidatesWithPreselection();
}
public void testOverloadWithOneIncompatibleVarargs() {
assertNotNull(doTest2CandidatesWithPreselection().getHighlightedParameter());
}
@NeedsIndex.ForStandardLibrary
public void testOverloadWithErrorOnTheTopLevel() {
@@ -178,7 +182,7 @@ public class ParameterInfoTest extends AbstractParameterInfoTestCase {
updateParameterInfoContext.isUIComponentEnabled(2));
}
private void doTest2CandidatesWithPreselection() {
private MockUpdateParameterInfoContext doTest2CandidatesWithPreselection() {
myFixture.configureByFile(getTestName(false) + ".java");
MethodParameterInfoHandler handler = new MethodParameterInfoHandler();
@@ -192,6 +196,7 @@ public class ParameterInfoTest extends AbstractParameterInfoTestCase {
ParameterInfoComponent.createContext(itemsToShow, getEditor(), handler, -1);
MockUpdateParameterInfoContext updateParameterInfoContext = updateParameterInfo(handler, list, itemsToShow);
assertTrue(updateParameterInfoContext.isUIComponentEnabled(0) || updateParameterInfoContext.isUIComponentEnabled(1));
return updateParameterInfoContext;
}
@NotNull