From f599645e1f9fbf6ce3c0618a8fd326c5f06c8e64 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Mon, 12 May 2014 12:46:55 +0400 Subject: [PATCH] fixed PY-12920 **kwargs in constructor parameters disappear after "Add super class call" quick fix --- .../quickfix/AddCallSuperQuickFix.java | 21 ++++++++++++------- .../AddCallSuperQuickFixTest/kwargs.py | 7 +++++++ .../AddCallSuperQuickFixTest/kwargs_after.py | 7 +++++++ .../quickFixes/AddCallSuperQuickFixTest.java | 4 ++++ 4 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 python/testData/quickFixes/AddCallSuperQuickFixTest/kwargs.py create mode 100644 python/testData/quickFixes/AddCallSuperQuickFixTest/kwargs_after.py diff --git a/python/src/com/jetbrains/python/inspections/quickfix/AddCallSuperQuickFix.java b/python/src/com/jetbrains/python/inspections/quickfix/AddCallSuperQuickFix.java index 27134f192d1c..c25714345005 100644 --- a/python/src/com/jetbrains/python/inspections/quickfix/AddCallSuperQuickFix.java +++ b/python/src/com/jetbrains/python/inspections/quickfix/AddCallSuperQuickFix.java @@ -24,6 +24,7 @@ import com.jetbrains.python.PyNames; import com.jetbrains.python.psi.*; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -139,7 +140,7 @@ public class AddCallSuperQuickFix implements LocalQuickFix { private static void addParametersFromSuper(@NotNull final PyFunction superInit, @NotNull final StringBuilder superCall, @NotNull final StringBuilder newFunction, boolean addComma, @NotNull final List problemParams, @NotNull final List functionParams, - String starName, String doubleStarName) { + @Nullable String starName, @Nullable String doubleStarName) { final PyParameterList paramList = superInit.getParameterList(); PyParameter[] parameters = paramList.getParameters(); boolean addDouble = false; @@ -170,16 +171,20 @@ public class AddCallSuperQuickFix implements LocalQuickFix { } for(String p : problemParams) newFunction.append(",").append(p); - if (addStar) { + if (starName != null) { newFunction.append(",").append(starName); - if (addComma) superCall.append(","); - superCall.append(starName); - addComma = true; + if (addStar) { + if (addComma) superCall.append(","); + superCall.append(starName); + addComma = true; + } } - if (addDouble) { - if (addComma) superCall.append(","); - superCall.append(doubleStarName); + if (doubleStarName != null) { newFunction.append(",").append(doubleStarName); + if (addDouble) { + if (addComma) superCall.append(","); + superCall.append(doubleStarName); + } } } } diff --git a/python/testData/quickFixes/AddCallSuperQuickFixTest/kwargs.py b/python/testData/quickFixes/AddCallSuperQuickFixTest/kwargs.py new file mode 100644 index 000000000000..e5a5ec0fff36 --- /dev/null +++ b/python/testData/quickFixes/AddCallSuperQuickFixTest/kwargs.py @@ -0,0 +1,7 @@ +class A(object): + def __init__(self): + pass + +class B(A): + def __init__(self, **kwargs): + pass \ No newline at end of file diff --git a/python/testData/quickFixes/AddCallSuperQuickFixTest/kwargs_after.py b/python/testData/quickFixes/AddCallSuperQuickFixTest/kwargs_after.py new file mode 100644 index 000000000000..b15ed35e3ccf --- /dev/null +++ b/python/testData/quickFixes/AddCallSuperQuickFixTest/kwargs_after.py @@ -0,0 +1,7 @@ +class A(object): + def __init__(self): + pass + +class B(A): + def __init__(self, **kwargs): + super(B, self).__init__() \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/quickFixes/AddCallSuperQuickFixTest.java b/python/testSrc/com/jetbrains/python/quickFixes/AddCallSuperQuickFixTest.java index 6ff97dcc4c24..a816abc2729d 100644 --- a/python/testSrc/com/jetbrains/python/quickFixes/AddCallSuperQuickFixTest.java +++ b/python/testSrc/com/jetbrains/python/quickFixes/AddCallSuperQuickFixTest.java @@ -30,4 +30,8 @@ public class AddCallSuperQuickFixTest extends PyQuickFixTestCase { public void testNewStyle() { doQuickFixTest(PyMissingConstructorInspection.class, PyBundle.message("QFIX.add.super")); } + + public void testKwargs() { + doQuickFixTest(PyMissingConstructorInspection.class, PyBundle.message("QFIX.add.super")); + } }