From 3529094fd2ec4935b0f5db339ad34963239fa878 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Tue, 4 Feb 2014 14:15:41 +0400 Subject: [PATCH] Get rid of grandparent for alignment. --- .../jetbrains/python/formatter/PyBlock.java | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index ef18524dd3bc..0c535c197424 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -142,23 +142,30 @@ public class PyBlock implements ASTBlock { Indent childIndent = Indent.getNoneIndent(); Alignment childAlignment = null; - //First we are going to set-up possible alignment to parents - PyBlock p = !breaksAlignment(parentType) ? myParent : null; - while (p != null) { - ASTNode pNode = p.getNode(); - if (ourListElementTypes.contains(pNode.getElementType())) { - if (needListAlignment(child) && !isEmptyList(_node.getPsi()) && !isInControlStatement()) { + if (parentType == PyElementTypes.BINARY_EXPRESSION && !isInControlStatement()) { + //Setup alignments for binary expression + childAlignment = getAlignmentForChildren(); + PyBlock p = myParent; //Check grandparents + while (p != null) { + ASTNode pNode = p.getNode(); + if (ourListElementTypes.contains(pNode.getElementType())) { + if (needListAlignment(child) && !isEmptyList(_node.getPsi())) { + + childAlignment = p.getChildAlignment(); + break; + } + } + else if (pNode == PyElementTypes.BINARY_EXPRESSION) { childAlignment = p.getChildAlignment(); + } + if (!breaksAlignment(pNode.getElementType())) { + p = p.myParent; + } + else { break; } } - if (!breaksAlignment(pNode.getElementType())) { - p = p.myParent; - } - else { - break; - } } if (childType == PyElementTypes.STATEMENT_LIST) { @@ -193,14 +200,6 @@ public class PyBlock implements ASTBlock { PyStatementPart.class); childIndent = parens != null ? Indent.getNormalIndent() : Indent.getContinuationIndent(); } - else { - if (grandparentType == PyElementTypes.BINARY_EXPRESSION && myParent != null) { - childAlignment = myParent.getAlignmentForChildren(); - } - else { - childAlignment = getAlignmentForChildren(); - } - } } if (parentType == PyElementTypes.LIST_LITERAL_EXPRESSION || parentType == PyElementTypes.LIST_COMP_EXPRESSION) {