failing test for alignment in binary expressions

This commit is contained in:
Dmitry Jemerov
2010-09-22 16:20:32 +04:00
parent f878a60c15
commit 2f2a74468d
4 changed files with 21 additions and 4 deletions
@@ -33,7 +33,7 @@ public class PyBlock implements ASTBlock {
private final Wrap _wrap;
private final CodeStyleSettings mySettings;
private List<PyBlock> _subBlocks = null;
private final Alignment _childListAlignment;
private Alignment myChildAlignment;
private static final boolean DUMP_FORMATTING_BLOCKS = false;
private static final TokenSet ourListElementTypes = TokenSet.create(PyElementTypes.LIST_LITERAL_EXPRESSION,
@@ -61,7 +61,6 @@ public class PyBlock implements ASTBlock {
_node = node;
_wrap = wrap;
mySettings = settings;
_childListAlignment = Alignment.createAlignment();
}
@NotNull
@@ -74,6 +73,13 @@ public class PyBlock implements ASTBlock {
return _node.getTextRange();
}
private Alignment getAlignmentForChildren() {
if (myChildAlignment == null) {
myChildAlignment = Alignment.createAlignment();
}
return myChildAlignment;
}
@NotNull
public List<Block> getSubBlocks() {
if (_subBlocks == null) {
@@ -131,9 +137,12 @@ public class PyBlock implements ASTBlock {
wrap = Wrap.createWrap(WrapType.NORMAL, true);
}
if (needListAlignment(child)) {
childAlignment = _childListAlignment;
childAlignment = getAlignmentForChildren();
}
}
else if (parentType == PyElementTypes.BINARY_EXPRESSION && PyElementTypes.EXPRESSIONS.contains(childType)) {
childAlignment = getAlignmentForChildren();
}
if (parentType == PyElementTypes.LIST_LITERAL_EXPRESSION) {
if (childType == PyTokenTypes.RBRACKET || childType == PyTokenTypes.LBRACKET) {
childIndent = Indent.getNoneIndent();
@@ -452,7 +461,7 @@ public class PyBlock implements ASTBlock {
private Alignment getChildAlignment() {
if (ourListElementTypes.contains(_node.getElementType())) {
return _childListAlignment;
return getAlignmentForChildren();
}
return null;
}
@@ -0,0 +1,2 @@
if isintance(True, bool) and\
isinstance(1, int): pass
@@ -0,0 +1,2 @@
if isintance(True, bool) and\
isinstance(1, int): pass
@@ -76,6 +76,10 @@ public class PyFormatterTest extends PyLightFixtureTestCase {
doTest();
}
public void testAlignInBinaryExpression() {
doTest();
}
private void doTest() {
myFixture.configureByFile("formatter/" + getTestName(true) + ".py");
ApplicationManager.getApplication().runWriteAction(new Runnable() {