introduce parameter: respect varargs when rise conflict on params count/args count mismatch (IDEA-56024)

This commit is contained in:
anna
2010-06-29 16:14:50 +04:00
parent 32f3cd7484
commit 57298b6cb2
3 changed files with 20 additions and 3 deletions
@@ -142,7 +142,8 @@ public class JavaIntroduceParameterMethodUsagesProcessor implements IntroducePar
public void findConflicts(IntroduceParameterData data, UsageInfo[] usages, final MultiMap<PsiElement, String> conflicts) {
final int parametersCount = data.getMethodToReplaceIn().getParameterList().getParametersCount();
final PsiMethod method = data.getMethodToReplaceIn();
final int parametersCount = method.getParameterList().getParametersCount();
for (UsageInfo usage : usages) {
if (!isMethodUsage(usage)) continue;
final PsiElement element = usage.getElement();
@@ -150,7 +151,8 @@ public class JavaIntroduceParameterMethodUsagesProcessor implements IntroducePar
final PsiExpressionList argList = call.getArgumentList();
if (argList != null) {
final int actualParamLength = argList.getExpressions().length;
if (actualParamLength < parametersCount) {
if ((method.isVarArgs() && actualParamLength + 1 < parametersCount) ||
(!method.isVarArgs() && actualParamLength < parametersCount)) {
conflicts.putValue(call, "Incomplete call(" + call.getText() +"): " + parametersCount + " parameters expected but only " + actualParamLength + " found");
}
data.getParametersToRemove().forEach(new TIntProcedure() {
@@ -0,0 +1,10 @@
class C {
void method(int k, String... s) {
System.out.println(s[<selection>k</selection>]);
}
{
method("a", "b", "c");
method();
}
}
@@ -168,7 +168,12 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase {
}
public void testParameterJavaDocBeforeVararg() throws Exception {
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false, true, false, "Incomplete call(method()): 1 parameters expected but only 0 found");
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false, true, false);
}
public void testIncompleteVararg() throws Exception {
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, true, false, true, false, "Incomplete call(method()): 2 parameters expected but only 0 found\n" +
"Incomplete call(method()): expected to delete the 0 parameter but only 0 parameters found");
}
public void testIncorrectScope() throws Exception {