fixed a case when formatter breaks code (PY-4034 comment)

This commit is contained in:
Dmitry Jemerov
2011-07-05 16:17:32 +02:00
parent cbd92451a1
commit 05ec420643
4 changed files with 23 additions and 2 deletions
@@ -177,7 +177,7 @@ public class PyBlock implements ASTBlock {
childIndent = Indent.getNormalIndent();
}
}
else if (parentType == PyElementTypes.PARENTHESIZED_EXPRESSION) {
else if (parentType == PyElementTypes.PARENTHESIZED_EXPRESSION && hasLineBreaksBefore(child, 1)) {
childIndent = Indent.getNormalIndent();
}
@@ -242,7 +242,8 @@ public class PyBlock implements ASTBlock {
}
private static boolean hasLineBreaksBefore(ASTNode child, int minCount) {
return isWhitespaceWithLineBreaks(TreeUtil.findLastLeaf(child.getTreePrev()), minCount) ||
final ASTNode treePrev = child.getTreePrev();
return (treePrev != null && isWhitespaceWithLineBreaks(TreeUtil.findLastLeaf(treePrev), minCount)) ||
isWhitespaceWithLineBreaks(child.getFirstChildNode(), minCount);
}
@@ -0,0 +1,8 @@
def bad_autoformat_example():
a = 5
b = 10
print a, b
(a, b) = b, a
print a, b
a, b = b, a
print a, b
@@ -0,0 +1,8 @@
def bad_autoformat_example():
a = 5
b = 10
print a, b
(a, b) = b, a
print a, b
a, b = b, a
print a, b
@@ -113,6 +113,10 @@ public class PyFormatterTest extends PyLightFixtureTestCase {
doTest();
}
public void testTupleAssignment() { // PY-4034 comment
doTest();
}
public void testPsiFormatting() { // IDEA-69724
String initial =
"def method_name(\n" +