inline: don't flatten multi dimensional array in varargs calls (IDEA-153700)

This commit is contained in:
Anna.Kozlova
2016-03-29 21:15:47 +02:00
parent ff6ad198eb
commit bb5a0f66e9
4 changed files with 28 additions and 0 deletions

View File

@@ -295,6 +295,11 @@ public class InlineUtil {
}
private static boolean isSafeToFlatten(PsiCall callExpression, PsiMethod oldRefMethod, PsiExpression[] arrayElements) {
for (PsiExpression arrayElement : arrayElements) {
if (arrayElement instanceof PsiArrayInitializerExpression) {
return false;
}
}
PsiCall copy = (PsiCall)callExpression.copy();
PsiExpressionList copyArgumentList = copy.getArgumentList();
LOG.assertTrue(copyArgumentList != null);

View File

@@ -0,0 +1,10 @@
import java.util.Arrays;
import java.util.List;
class Main {
public static void main(String[] args) {
Object[][] pa<caret>rams = new Object[][]{{""}, {""}};
List<Object[]> l1 = Arrays.asList(params);
}
}

View File

@@ -0,0 +1,9 @@
import java.util.Arrays;
import java.util.List;
class Main {
public static void main(String[] args) {
List<Object[]> l1 = Arrays.asList(new Object[][]{{""}, {""}});
}
}

View File

@@ -260,6 +260,10 @@ public class InlineLocalTest extends LightCodeInsightTestCase {
doTest(true);
}
public void testDontOpenMultidimensionalArrays() throws Exception {
doTest(false);
}
public void testLocalVarInsideLambdaBodyWriteUsage() throws Exception {
doTest(true, "Cannot perform refactoring.\n" +
"Variable 'hello' is accessed for writing");