PY-15143 Do not allow to remove default value from parameter without any replacement...
authorMikhail Golubev <mikhail.golubev@jetbrains.com>
Wed, 25 Feb 2015 14:14:46 +0000 (17:14 +0300)
committerMikhail Golubev <mikhail.golubev@jetbrains.com>
Wed, 25 Feb 2015 16:37:11 +0000 (19:37 +0300)
python/src/com/jetbrains/python/refactoring/changeSignature/PyChangeSignatureDialog.java
python/testData/refactoring/changeSignature/removeDefaultFromParamWithoutReplacement.py [new file with mode: 0644]
python/testSrc/com/jetbrains/python/refactoring/changeSignature/PyChangeSignatureTest.java

index 97b83c6e16996b60c2167931b6b6fd7542e6be6d..69b7a168b0dd767601c7785583141d2119fa2fe7 100644 (file)
@@ -199,15 +199,22 @@ public class PyChangeSignatureDialog extends ChangeSignatureDialogBase<PyParamet
           }
         }
       }
-      if (parameter.getOldIndex() < 0 && !parameter.getName().startsWith("*")) {
-        if (StringUtil.isEmpty(info.defaultValueCodeFragment.getText()))
+      if (parameter.getOldIndex() < 0) {
+        if (!parameter.getName().startsWith("*")) {
+          if (StringUtil.isEmpty(info.defaultValueCodeFragment.getText())) {
+            return PyBundle.message("refactoring.change.signature.dialog.validation.default.missing");
+          }
+          if (StringUtil.isEmptyOrSpaces(parameter.getName())) {
+            return PyBundle.message("refactoring.change.signature.dialog.validation.parameter.missing");
+          }
+        }
+      }
+      else if (myMethod.getParameters().get(parameter.getOldIndex()).getDefaultInSignature() &&
+               StringUtil.isEmptyOrSpaces(parameter.getDefaultValue())) {
           return PyBundle.message("refactoring.change.signature.dialog.validation.default.missing");
-        if (StringUtil.isEmptyOrSpaces(parameter.getName()))
-          return PyBundle.message("refactoring.change.signature.dialog.validation.parameter.missing");
       }
     }
 
-
     return null;
   }
 
diff --git a/python/testData/refactoring/changeSignature/removeDefaultFromParamWithoutReplacement.py b/python/testData/refactoring/changeSignature/removeDefaultFromParamWithoutReplacement.py
new file mode 100644 (file)
index 0000000..df36c44
--- /dev/null
@@ -0,0 +1,6 @@
+def print_arg(arg=100):
+    print arg
+
+
+def test():
+    print_arg()
index 0a66b1e6bf71fc39c9b6c9d51d01ae50e68027dd..14984c95887726b240e75dff11421a4f23b5e8df 100644 (file)
@@ -34,6 +34,7 @@ import java.util.List;
 /**
  * User : ktisha
  */
+@SuppressWarnings("ArraysAsListWithZeroOrOneArgument")
 @TestDataPath("$CONTENT_ROOT/../testData/")
 public class PyChangeSignatureTest extends PyTestCase {
 
@@ -79,6 +80,13 @@ public class PyChangeSignatureTest extends PyTestCase {
     doChangeSignatureTest(null, Arrays.asList(new PyParameterInfo(0, "a", null, false), new PyParameterInfo(1, "b", "2", false)));
   }
 
+  // PY-15143
+  public void testRemoveDefaultFromParamWithoutReplacement() {
+    final PyParameterInfo first = new PyParameterInfo(0, "arg", null, false);
+    final PyParameterInfo second = new PyParameterInfo(-1, "vvv", "xxx", false);
+    doValidationTest(null, Arrays.asList(first, second), PyBundle.message("refactoring.change.signature.dialog.validation.default.missing"));
+  }
+
   public void testAddDefaultParam1() {
     doChangeSignatureTest(null, Arrays.asList(new PyParameterInfo(0, "a", null, false), new PyParameterInfo(-1, "d", "1", true),
                                               new PyParameterInfo(1, "b", "None", true)));
@@ -193,11 +201,11 @@ public class PyChangeSignatureTest extends PyTestCase {
   }
 
   public void testNonDefaultAfterDefault() {
-    doValidationTest(null, Arrays.asList(new PyParameterInfo(-1, "a", "2", false), new PyParameterInfo(1, "b", "2", false)), null);
+    doValidationTest(null, Arrays.asList(new PyParameterInfo(-1, "a", "2", false), new PyParameterInfo(0, "b", "2", false)), null);
   }
 
   public void testNonDefaultAfterDefault1() {
-    doValidationTest(null, Arrays.asList(new PyParameterInfo(1, "b", "1", true), new PyParameterInfo(-1, "a", "2", false)),
+    doValidationTest(null, Arrays.asList(new PyParameterInfo(0, "b", "1", true), new PyParameterInfo(-1, "a", "2", false)),
                      PyBundle.message("ANN.non.default.param.after.default"));
   }