diff --git a/python/src/com/jetbrains/python/inspections/PyMissingConstructorInspection.java b/python/src/com/jetbrains/python/inspections/PyMissingConstructorInspection.java
index 90871800c2bc..c5b579270c93 100644
--- a/python/src/com/jetbrains/python/inspections/PyMissingConstructorInspection.java
+++ b/python/src/com/jetbrains/python/inspections/PyMissingConstructorInspection.java
@@ -70,7 +70,7 @@ public class PyMissingConstructorInspection extends PyInspection {
}
if (superClasses.length == 1 || node.isNewStyleClass())
registerProblem(initMethod.getNameIdentifier(), PyBundle.message("INSP.missing.super.constructor.message"),
- new AddCallSuperQuickFix(node.getSuperClasses()[0], superClasses[0].getText()));
+ new AddCallSuperQuickFix());
else
registerProblem(initMethod.getNameIdentifier(), PyBundle.message("INSP.missing.super.constructor.message"));
}
diff --git a/python/src/com/jetbrains/python/inspections/quickfix/AddCallSuperQuickFix.java b/python/src/com/jetbrains/python/inspections/quickfix/AddCallSuperQuickFix.java
index 2306a478adaa..27134f192d1c 100644
--- a/python/src/com/jetbrains/python/inspections/quickfix/AddCallSuperQuickFix.java
+++ b/python/src/com/jetbrains/python/inspections/quickfix/AddCallSuperQuickFix.java
@@ -38,13 +38,6 @@ import java.util.List;
* User: catherine
*/
public class AddCallSuperQuickFix implements LocalQuickFix {
- private final PyClass mySuper;
- private String mySuperName;
-
- public AddCallSuperQuickFix(PyClass superClass, String superName) {
- mySuper = superClass;
- mySuperName = superName;
- }
@NotNull
public String getName() {
@@ -60,12 +53,17 @@ public class AddCallSuperQuickFix implements LocalQuickFix {
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
PyFunction problemFunction = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PyFunction.class);
if (problemFunction == null) return;
- PyFunction superInit = mySuper.findMethodByName(PyNames.INIT, true);
+ final StringBuilder superCall = new StringBuilder();
+ final PyClass klass = problemFunction.getContainingClass();
+ if (klass == null) return;
+ final PyClass[] superClasses = klass.getSuperClasses();
+ if (superClasses.length == 0) return;
+
+ final PyClass superClass = superClasses[0];
+ final PyFunction superInit = superClass.findMethodByName(PyNames.INIT, true);
if (superInit == null) return;
- StringBuilder superCall = new StringBuilder();
- PyClass klass = problemFunction.getContainingClass();
boolean addComma = true;
- if (klass != null && klass.isNewStyleClass()) {
+ if (klass.isNewStyleClass()) {
addComma = false;
if (LanguageLevel.forElement(klass).isPy3K())
superCall.append("super().__init__(");
@@ -73,7 +71,7 @@ public class AddCallSuperQuickFix implements LocalQuickFix {
superCall.append("super(").append(klass.getName()).append(", self).__init__(");
}
else {
- superCall.append(mySuperName);
+ superCall.append(superClass.getName());
superCall.append(".__init__(self");
}
StringBuilder newFunction = new StringBuilder("def __init__(self");
@@ -83,7 +81,7 @@ public class AddCallSuperQuickFix implements LocalQuickFix {
superCall.append(")");
final PyStatementList statementList = problemFunction.getStatementList();
PyExpression docstring = null;
- final PyStatement[] statements = statementList == null ? new PyStatement[0] : statementList.getStatements();
+ final PyStatement[] statements = statementList.getStatements();
if (statements.length != 0 && statements[0] instanceof PyExpressionStatement) {
PyExpressionStatement st = (PyExpressionStatement)statements[0];
if (st.getExpression() instanceof PyStringLiteralExpression)
diff --git a/python/testData/quickFixes/AddCallSuperQuickFixTest/newStyle.py b/python/testData/quickFixes/AddCallSuperQuickFixTest/newStyle.py
new file mode 100644
index 000000000000..7eec148d833f
--- /dev/null
+++ b/python/testData/quickFixes/AddCallSuperQuickFixTest/newStyle.py
@@ -0,0 +1,11 @@
+
+class A(object):
+ def __init__(self):
+ a = 1
+
+class C(A):
+ def __init__(self):
+ pass
+
+ def foo(self):
+ pass
\ No newline at end of file
diff --git a/python/testData/quickFixes/AddCallSuperQuickFixTest/newStyle_after.py b/python/testData/quickFixes/AddCallSuperQuickFixTest/newStyle_after.py
new file mode 100644
index 000000000000..08cded37a594
--- /dev/null
+++ b/python/testData/quickFixes/AddCallSuperQuickFixTest/newStyle_after.py
@@ -0,0 +1,11 @@
+
+class A(object):
+ def __init__(self):
+ a = 1
+
+class C(A):
+ def __init__(self):
+ super(C, self).__init__()
+
+ def foo(self):
+ pass
\ No newline at end of file
diff --git a/python/testData/quickFixes/AddCallSuperQuickFixTest/oldStyle.py b/python/testData/quickFixes/AddCallSuperQuickFixTest/oldStyle.py
new file mode 100644
index 000000000000..513af7d80b35
--- /dev/null
+++ b/python/testData/quickFixes/AddCallSuperQuickFixTest/oldStyle.py
@@ -0,0 +1,10 @@
+class A():
+ def __init__(self):
+ a = 1
+
+class C(A):
+ def __init__(self):
+ pass
+
+ def foo(self):
+ pass
\ No newline at end of file
diff --git a/python/testData/quickFixes/AddCallSuperQuickFixTest/oldStyle_after.py b/python/testData/quickFixes/AddCallSuperQuickFixTest/oldStyle_after.py
new file mode 100644
index 000000000000..d1ee14124e7e
--- /dev/null
+++ b/python/testData/quickFixes/AddCallSuperQuickFixTest/oldStyle_after.py
@@ -0,0 +1,10 @@
+class A():
+ def __init__(self):
+ a = 1
+
+class C(A):
+ def __init__(self):
+ A.__init__(self)
+
+ def foo(self):
+ pass
\ 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
new file mode 100644
index 000000000000..6ff97dcc4c24
--- /dev/null
+++ b/python/testSrc/com/jetbrains/python/quickFixes/AddCallSuperQuickFixTest.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2000-2013 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.jetbrains.python.quickFixes;
+
+import com.intellij.testFramework.TestDataPath;
+import com.jetbrains.python.PyBundle;
+import com.jetbrains.python.PyQuickFixTestCase;
+import com.jetbrains.python.inspections.PyMissingConstructorInspection;
+
+@TestDataPath("$CONTENT_ROOT/../testData//quickFixes/AddCallSuperQuickFixTest/")
+public class AddCallSuperQuickFixTest extends PyQuickFixTestCase {
+
+ public void testOldStyle() {
+ doQuickFixTest(PyMissingConstructorInspection.class, PyBundle.message("QFIX.add.super"));
+ }
+
+ public void testNewStyle() {
+ doQuickFixTest(PyMissingConstructorInspection.class, PyBundle.message("QFIX.add.super"));
+ }
+}