mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-2583 wrong list comprehension to for loop
This commit is contained in:
+13
-1
@@ -127,15 +127,27 @@ public class ReplaceListComprehensionWithForIntention implements IntentionAction
|
||||
ComprhForComponent comp = forComps.get(0);
|
||||
PyForStatement pyForStatement = elementGenerator.createFromText(LanguageLevel.forElement(expression), PyForStatement.class,
|
||||
"for " + comp.getIteratorVariable().getText() + " in "+ comp.getIteratedList().getText() + ":\n a+1");
|
||||
|
||||
List<ComprhIfComponent> ifComps = ((PyListCompExpression)expression).getIfComponents();
|
||||
if (ifComps.size() != 0) {
|
||||
addIfComponents(pyForStatement, ifComps, elementGenerator);
|
||||
}
|
||||
PyStatement toReplace = pyForStatement.getForPart().getStatementList().getStatements()[0];
|
||||
while (toReplace instanceof PyIfStatement) {
|
||||
toReplace = ((PyIfStatement)toReplace).getIfPart().getStatementList().getStatements()[0];
|
||||
}
|
||||
toReplace.replace(statement);
|
||||
addForComponents(pyForStatement, ((PyListCompExpression)expression).getResultExpression(), elementGenerator, result);
|
||||
pyStatement.replace(pyForStatement);
|
||||
statement.getForPart().replace(pyForStatement);
|
||||
}
|
||||
}
|
||||
else {
|
||||
while (pyStatement instanceof PyForStatement) {
|
||||
pyStatement = ((PyForStatement)pyStatement).getForPart().getStatementList().getStatements()[0];
|
||||
while (pyStatement instanceof PyIfStatement) {
|
||||
pyStatement = ((PyIfStatement)pyStatement).getIfPart().getStatementList().getStatements()[0];
|
||||
}
|
||||
}
|
||||
pyStatement.replace(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
a = 2
|
||||
smth = []
|
||||
for z in xrange(14):
|
||||
if z != 3:
|
||||
if z != 8:
|
||||
for x in xrange(10):
|
||||
if x != 2:
|
||||
if x != 5:
|
||||
for y in xrange(12):
|
||||
if y != 1:
|
||||
if y != 4:
|
||||
for x in xrange(10):
|
||||
if x != 2:
|
||||
if x != 5:
|
||||
for z in xrange(14):
|
||||
if z != 3:
|
||||
if z != 8:
|
||||
smth.append(x + y + z)
|
||||
|
||||
a = 5
|
||||
Reference in New Issue
Block a user