fixed list creation quick fix. Added tests.

This commit is contained in:
Ekaterina Tuzova
2011-01-26 16:50:15 +03:00
parent 0cd3f9d7d8
commit 8378e03b79
4 changed files with 16 additions and 2 deletions
@@ -53,7 +53,9 @@ public class PyListCreationInspection extends PyInspection {
PyCallExpression callExpression = (PyCallExpression)statement;
PyExpression callee = callExpression.getCallee();
if (callee instanceof PyQualifiedExpression) {
if (((PyQualifiedExpression)callee).getQualifier().getText().equals(name)) {
PyExpression qualifier = ((PyQualifiedExpression)callee).getQualifier();
String funcName = ((PyQualifiedExpression)callee).getReferencedName();
if (qualifier != null && qualifier.getText().equals(name) && "append".equals(funcName)) {
PyArgumentList argList = callExpression.getArgumentList();
if (argList != null) {
for (PyExpression argument : argList.getArguments()) {
@@ -62,13 +64,14 @@ public class PyListCreationInspection extends PyInspection {
availableFix = true;
}
}
if(availableFix)
quickFix.addStatement(expressionStatement);
}
}
}
if (quickFix == null) {
return;
}
quickFix.addStatement(expressionStatement);
expressionStatement = PsiTreeUtil.getNextSiblingOfType(expressionStatement, PyExpressionStatement.class);
if (expressionStatement != null)
statement = expressionStatement.getExpression();
@@ -0,0 +1,4 @@
<warning descr="This list creation could be rewritten as a list literal">my_<caret>list = [m]</warning>
my_list.append(1)
my_list.append(var)
do_something()
@@ -0,0 +1,2 @@
my_list = [m, 1, var]
do_something()
@@ -215,6 +215,11 @@ public class PyQuickFixTest extends PyLightFixtureTestCase {
PyBundle.message("INTN.replace.noteq.operator"), true, true);
}
public void testListCreation() {
doInspectionTest("ListCreation.py", PyListCreationInspection.class,
PyBundle.message("QFIX.list.creation"), true, true);
}
@Override
@NonNls
protected String getTestDataPath() {