IDEA-126171

This commit is contained in:
Alexey Kudravtsev
2014-07-01 13:23:10 +04:00
parent 5a48d2c129
commit 48bfcde50a
4 changed files with 51 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,14 +64,25 @@ public class SliceUtil {
expression = ((PsiArrayAccessExpression)expression).getArrayExpression();
indexNesting++;
}
if (expression instanceof PsiExpressionList && indexNesting != 0 && expression.getParent() instanceof PsiMethodCallExpression) {
PsiElement par = expression == null ? null : expression.getParent();
if (expression instanceof PsiExpressionList && par instanceof PsiMethodCallExpression) {
// expression list ends up here if we track varargs
// unfold varargs list into individual expressions
PsiExpression[] expressions = ((PsiExpressionList)expression).getExpressions();
for (PsiExpression arg : expressions) {
if (!handToProcessor(arg, processor, parent, parentSubstitutor, indexNesting -1, syntheticField)) return false;
PsiMethod method = ((PsiMethodCallExpression)par).resolveMethod();
if (method != null) {
int parametersCount = method.getParameterList().getParametersCount();
if (parametersCount != 0) {
// unfold varargs list into individual expressions
PsiExpression[] expressions = ((PsiExpressionList)expression).getExpressions();
if (indexNesting != 0) {
// should skip not-vararg arguments
for (int i = parametersCount-1; i < expressions.length; i++) {
PsiExpression arg = expressions[i];
if (!handToProcessor(arg, processor, parent, parentSubstitutor, indexNesting - 1, syntheticField)) return false;
}
}
return true;
}
}
return true;
}
boolean needToReportDeclaration = false;
@@ -409,7 +420,6 @@ public class SliceUtil {
PsiType actualExpressionType;
if (actualParameterType instanceof PsiEllipsisType) {
passExpression = argumentList;
//passExpression = createArrayInitializerFromExpressions(argumentList, ((PsiEllipsisType)actualType).getComponentType(), expressions);
actualExpressionType = expressions[paramSeqNo].getType();
}
else {
@@ -446,6 +456,10 @@ public class SliceUtil {
if (substituted == null) return true;
PsiType typeToCheck;
if (actualParameterType instanceof PsiEllipsisType) {
// there may be the case of passing the vararg argument to the other vararg method: foo(int... ints) { bar(ints); } bar(int... ints) {}
if (TypeConversionUtil.areTypesConvertible(substituted, actualParameterType)) {
return handToProcessor(expressions[paramSeqNo], processor, parent, combined, indexNesting, syntheticField);
}
typeToCheck = ((PsiEllipsisType)actualParameterType).getComponentType();
}
else {

View File

@@ -0,0 +1,12 @@
class VarArgs {
private void g() {
f<flown111>("d",1,2,3);
}
void f(String value,int... <flown11>i) {
v(value, <flown1>i);
}
private void v(String value, int... <caret>ints) {
}
}

View File

@@ -0,0 +1,14 @@
class VarArgs {
private static void foo(String value, int...<flown11>ints) {
System.out.println(value + " " + java.util.Arrays.asList(ints));
int <caret>anInt = <flown1>ints[1];
}
private static void bar(String value, int...<flown1111>ints) {
foo(value, <flown111>ints);
}
private static void baz(String value) {
bar<flown11111>("d", <flown111111>2, <flown111112>3, <flown111113>4);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -179,6 +179,8 @@ public class SliceBackwardTest extends SliceTestCase {
public void testArrayElements() throws Exception { doTest();}
public void testAnonArray() throws Exception { doTest();}
public void testVarArgs() throws Exception { doTest();}
public void testVarArgsAsAWhole() throws Exception { doTest();}
public void testVarArgsPartial() throws Exception { doTest();}
public void testListTrackToArray() throws Exception { doTest();}
}