PY-16348 Preserve line comments inside the body of updated constructor

This commit is contained in:
Mikhail Golubev
2015-07-01 14:31:30 +03:00
parent a6a63cd53c
commit 7c0bf23f2d
4 changed files with 36 additions and 5 deletions
@@ -116,12 +116,16 @@ public class AddCallSuperQuickFix implements LocalQuickFix {
}
newFunction.append(superCall).append("\n\t");
boolean first = true;
for (PyStatement statement : statementList.getStatements()) {
if (first && docstring != null || statement instanceof PyPassStatement) {
first = false;
continue;
for (PsiElement child = statementList.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child instanceof PyStatement) {
if (first && docstring != null || child instanceof PyPassStatement) {
first = false;
continue;
}
}
if (child instanceof PyStatement || child instanceof PsiComment) {
newFunction.append(child.getText()).append("\n\t");
}
newFunction.append(statement.getText()).append("\n\t");
}
final PyElementGenerator generator = PyElementGenerator.getInstance(project);
@@ -0,0 +1,11 @@
class A:
def __init__(self):
pass
class B(A):
def <warning descr="Call to __init__ of super class is missed">__in<caret>it__</warning>(self):
# comment #1
pass
# comment #2
print 42
@@ -0,0 +1,11 @@
class A:
def __init__(self):
pass
class B(A):
def __init__(self):
A.__init__(self)
# comment #1
# comment #2
print 42
@@ -379,6 +379,11 @@ public class PyQuickFixTest extends PyTestCase {
doInspectionTest(PyMissingConstructorInspection.class, PyBundle.message("QFIX.add.super"), true, true);
}
// PY-16348
public void testAddCallSuperCommentsInFunctionBodyPreserved() {
doInspectionTest(PyMissingConstructorInspection.class, PyBundle.message("QFIX.add.super"), true, true);
}
// PY-491, PY-13297
public void testAddEncoding() {
doInspectionTest(PyMandatoryEncodingInspection.class, PyBundle.message("QFIX.add.encoding"), true, true);