diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlockGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlockGenerator.java index 5aee613507e2..ae7a2df6e967 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlockGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/GroovyBlockGenerator.java @@ -119,33 +119,37 @@ public class GroovyBlockGenerator implements GroovyElementTypes { // For Parameter lists if (isListLikeClause(blockPsi)) { final ArrayList subBlocks = new ArrayList(); - ASTNode[] children = node.getChildren(null); ASTNode prevChildNode = null; - final Alignment alignment = mustAlign(blockPsi, mySettings, children) ? Alignment.createAlignment() : null; - for (ASTNode childNode : children) { - if (canBeCorrectBlock(childNode)) { - final Indent indent = GroovyIndentProcessor.getChildIndent(block, prevChildNode, childNode); - subBlocks.add(new GroovyBlock(childNode, isKeyword(childNode) ? null : alignment, indent, myWrap, mySettings)); - prevChildNode = childNode; - } + final Alignment alignment = mustAlign(blockPsi, mySettings, node.getChildren(null)) ? Alignment.createAlignment() : null; + for (ASTNode childNode : visibleChildren(node)) { + final Indent indent = GroovyIndentProcessor.getChildIndent(block, prevChildNode, childNode); + subBlocks.add(new GroovyBlock(childNode, isKeyword(childNode) ? null : alignment, indent, myWrap, mySettings)); + prevChildNode = childNode; } return subBlocks; } // For other cases final ArrayList subBlocks = new ArrayList(); - ASTNode[] children = getGroovyChildren(node); ASTNode prevChildNode = null; - for (ASTNode childNode : children) { - if (canBeCorrectBlock(childNode)) { - final Indent indent = GroovyIndentProcessor.getChildIndent(block, prevChildNode, childNode); - subBlocks.add(new GroovyBlock(childNode, blockPsi instanceof GrCodeBlock ? null : myAlignment, indent, myWrap, mySettings)); - prevChildNode = childNode; - } + for (ASTNode childNode : visibleChildren(node)) { + final Indent indent = GroovyIndentProcessor.getChildIndent(block, prevChildNode, childNode); + subBlocks.add(new GroovyBlock(childNode, blockPsi instanceof GrCodeBlock ? null : myAlignment, indent, myWrap, mySettings)); + prevChildNode = childNode; } return subBlocks; } + private static List visibleChildren(ASTNode node) { + ArrayList list = new ArrayList(); + for (ASTNode astNode : getGroovyChildren(node)) { + if (canBeCorrectBlock(astNode)) { + list.add(astNode); + } + } + return list; + } + private static boolean mustAlign(PsiElement blockPsi, CodeStyleSettings mySettings, ASTNode[] children) { // We don't want to align single call argument if it's a closure. The reason is that it looks better to have call like // @@ -280,13 +284,11 @@ public class GroovyBlockGenerator implements GroovyElementTypes { final ArrayList subBlocks = new ArrayList(); Alignment alignment = mySettings.ALIGN_MULTILINE_BINARY_OPERATION ? Alignment.createAlignment() : null; GrBinaryExpression myExpr = (GrBinaryExpression) node.getPsi(); - ASTNode[] children = node.getChildren(null); if (myExpr.getLeftOperand() instanceof GrBinaryExpression) { addBinaryChildrenRecursively(myExpr.getLeftOperand(), subBlocks, Indent.getContinuationWithoutFirstIndent(), alignment, myWrap, mySettings); } - for (ASTNode childNode : children) { - if (canBeCorrectBlock(childNode) && - !(childNode.getPsi() instanceof GrBinaryExpression)) { + for (ASTNode childNode : visibleChildren(node)) { + if (!(childNode.getPsi() instanceof GrBinaryExpression)) { subBlocks.add(new GroovyBlock(childNode, alignment, Indent.getContinuationWithoutFirstIndent(), myWrap, mySettings)); } } @@ -309,16 +311,14 @@ public class GroovyBlockGenerator implements GroovyElementTypes { Indent indent, Alignment alignment, Wrap myWrap, CodeStyleSettings mySettings) { if (elem == null) return; - ASTNode[] children = elem.getNode().getChildren(null); // For binary expressions if ((elem instanceof GrBinaryExpression)) { GrBinaryExpression myExpr = ((GrBinaryExpression) elem); if (myExpr.getLeftOperand() instanceof GrBinaryExpression) { addBinaryChildrenRecursively(myExpr.getLeftOperand(), list, Indent.getContinuationWithoutFirstIndent(), alignment, myWrap, mySettings); } - for (ASTNode childNode : children) { - if (canBeCorrectBlock(childNode) && - !(childNode.getPsi() instanceof GrBinaryExpression)) { + for (ASTNode childNode : visibleChildren(elem.getNode())) { + if (!(childNode.getPsi() instanceof GrBinaryExpression)) { list.add(new GroovyBlock(childNode, alignment, indent, myWrap, mySettings)); } }