inline: substitute ellipsis type before array construction (IDEA-65897)

This commit is contained in:
anna
2011-02-27 18:20:25 +01:00
parent 70308b234e
commit e68c92c49f
4 changed files with 21 additions and 2 deletions

View File

@@ -606,9 +606,9 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
@NonNls String defaultValue;
if (paramType instanceof PsiEllipsisType) {
final PsiEllipsisType ellipsisType = (PsiEllipsisType)paramType;
paramType = ellipsisType.toArrayType();
paramType = callSubstitutor.substitute(ellipsisType.toArrayType());
if (applicabilityLevel == MethodCandidateInfo.ApplicabilityLevel.VARARGS) {
defaultValue = "new " + ellipsisType.getComponentType().getCanonicalText() + "[]{}";
defaultValue = "new " + ((PsiArrayType)paramType).getComponentType().getCanonicalText() + "[]{}";
}
else {
defaultValue = PsiTypesUtil.getDefaultValueOfType(paramType);

View File

@@ -0,0 +1,9 @@
class Test {
<T> void doSmth(T... ps) {
System.out.println(ps);
}
void m() {
doS<caret>mth(1, 2, 3);
}
}

View File

@@ -0,0 +1,6 @@
class Test {
void m() {
System.out.println(new Integer[]{1, 2, 3});
}
}

View File

@@ -165,6 +165,10 @@ public class InlineMethodTest extends LightCodeInsightTestCase {
doTest();
}
public void testArrayTypeInferenceFromVarargs() throws Exception {
doTest();
}
private void doTest() throws Exception {
String name = getTestName(false);
@NonNls String fileName = "/refactoring/inlineMethod/" + name + ".java";