inline varargs parameter in calls when method is inlined (IDEADEV-41353)

This commit is contained in:
anna
2010-01-14 14:28:47 +03:00
parent f4e148f0d5
commit eced11faaf
8 changed files with 66 additions and 4 deletions
@@ -777,6 +777,8 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
PsiExpression expr = InlineUtil.inlineVariable(variable, initializer, javaRef);
InlineUtil.tryToInlineArrayCreationForVarargs(expr);
//Q: move the following code to some util? (addition to inline?)
if (expr instanceof PsiThisExpression) {
if (expr.getParent() instanceof PsiReferenceExpression) {
@@ -864,6 +866,17 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
}
else if (initializer instanceof PsiCallExpression) {
if (accessCount > 1) return false;
if (initializer instanceof PsiNewExpression) {
final PsiArrayInitializerExpression arrayInitializer = ((PsiNewExpression)initializer).getArrayInitializer();
if (arrayInitializer != null) {
for (PsiExpression expression : arrayInitializer.getInitializers()) {
if (!canInlineParmOrThisVariable(expression, shouldBeFinal, strictlyFinal, accessCount, false)) {
return false;
}
}
return true;
}
}
final PsiExpressionList argumentList = ((PsiCallExpression)initializer).getArgumentList();
if (argumentList == null) return false;
final PsiExpression[] expressions = argumentList.getExpressions();
@@ -0,0 +1,16 @@
class Varargs {
void xxx() {
foo(new String[] {"aa", "hh"});
}
void <caret>foo(String... ss) {
bar(ss);
}
void bar(String s, String ss){
}
void bar(String... ss) {
}
}
@@ -0,0 +1,12 @@
class Varargs {
void xxx() {
bar(new String[] {"aa", "hh"});
}
void bar(String s, String ss){
}
void bar(String... ss) {
}
}
@@ -0,0 +1,12 @@
class Varargs {
void xxx() {
foo(new String[] {"aa", "hh"});
}
void <caret>foo(String... ss) {
bar(ss);
}
void bar(String... ss) {
}
}
@@ -0,0 +1,8 @@
class Varargs {
void xxx() {
bar("aa", "hh");
}
void bar(String... ss) {
}
}
@@ -4,7 +4,6 @@ public class Varargs {
}
public void foo() {
String[] texts = new String[]{"i", "d", "e", "a"};
String s = join("", texts);
String s = join("", "i", "d", "e", "a");
}
}
@@ -1,8 +1,7 @@
class BugTest {
{
String[] s = new String[] {""};
for (String s1 : s) {
for (String s1 : new String[] {""}) {
}
}
@@ -98,6 +98,9 @@ public class InlineMethodTest extends LightCodeInsightTestCase {
public void testVarargs1() throws Exception { doTest(); }
public void testFlatVarargs() throws Exception {doTest();}
public void testFlatVarargs1() throws Exception {doTest();}
public void testEnumConstructor() throws Exception { doTest(); }
public void testEnumConstantConstructorParameter() throws Exception { // IDEADEV-26133