change signature: refresh type element after normalizeDeclaration for old style arrays
authorAnna.Kozlova <anna.kozlova@jetbrains.com>
Tue, 15 Nov 2016 16:50:43 +0000 (17:50 +0100)
committerAnna.Kozlova <anna.kozlova@jetbrains.com>
Tue, 15 Nov 2016 17:11:31 +0000 (18:11 +0100)
java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageProcessor.java
java/java-tests/testData/refactoring/changeSignature/ReplaceOldStyleArrayWithVarargs.java [new file with mode: 0644]
java/java-tests/testData/refactoring/changeSignature/ReplaceOldStyleArrayWithVarargs_after.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureTest.java

index 1d88043954043516d2b9fb34c02717ad52846b57..8a7d6304ffbbf6bad77d6765122604bdb8bd1a9e 100644 (file)
@@ -827,11 +827,12 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
           parameter.getNameIdentifier().replace(newIdentifier);
         }
 
-        final PsiTypeElement typeElement = parameter.getTypeElement();
+        PsiTypeElement typeElement = parameter.getTypeElement();
         if (typeElement != null) {
+          parameter.normalizeDeclaration();
+          typeElement = parameter.getTypeElement();
           String oldType = oldParameterTypes[index];
           if (!oldType.equals(info.getTypeText())) {
-            parameter.normalizeDeclaration();
             PsiType newType =
               substitutor.substitute(info.createType(changeInfo.getMethod().getParameterList(), changeInfo.getMethod().getManager()));
             typeElement.replace(factory.createTypeElement(newType));
diff --git a/java/java-tests/testData/refactoring/changeSignature/ReplaceOldStyleArrayWithVarargs.java b/java/java-tests/testData/refactoring/changeSignature/ReplaceOldStyleArrayWithVarargs.java
new file mode 100644 (file)
index 0000000..a647a98
--- /dev/null
@@ -0,0 +1,3 @@
+class Test {
+  void <caret>foo(int a[]) {}
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/refactoring/changeSignature/ReplaceOldStyleArrayWithVarargs_after.java b/java/java-tests/testData/refactoring/changeSignature/ReplaceOldStyleArrayWithVarargs_after.java
new file mode 100644 (file)
index 0000000..dfb7f5a
--- /dev/null
@@ -0,0 +1,3 @@
+class Test {
+  void foo(int... a) {}
+}
\ No newline at end of file
index c3e690487d910cb8721c41222a4174cff0267c1c..15dd066297a2c7819592f58419abae8fc864959d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -355,6 +355,10 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
     }, false);
   }
 
+  public void testReplaceOldStyleArrayWithVarargs() throws Exception {
+    doTest(null, new ParameterInfoImpl[] {new ParameterInfoImpl(0, "a", new PsiEllipsisType(PsiType.INT))}, false);
+  }
+
   public void testReorderParamsOfFunctionalInterface() {
     doTest(null, null, null, method -> new ParameterInfoImpl[]{
       new ParameterInfoImpl(1, "b", PsiType.INT),