mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed list creation quick fix. Added tests.
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user