From 6a7e72bfc544ea240df574f5414548aefc28973b Mon Sep 17 00:00:00 2001 From: Andrey Ponomarev Date: Wed, 20 Feb 2013 16:42:24 +0100 Subject: [PATCH] Refactoring: build subblocks of JetBlock in one pass --- .../jet/plugin/formatter/JetBlock.java | 28 +++---------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java index 268cb831ff7..6e088272a2b 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java @@ -79,7 +79,7 @@ public class JetBlock extends AbstractBlock { private List buildSubBlocks() { List blocks = new ArrayList(); - Map childrenAlignments = createChildrenAlignments(); + ASTAlignmentStrategy childrenAlignmentStrategy = getChildrenAlignmentStrategy(); for (ASTNode child = myNode.getFirstChildNode(); child != null; child = child.getTreeNext()) { IElementType childType = child.getElementType(); @@ -90,7 +90,7 @@ public class JetBlock extends AbstractBlock { continue; } - Alignment childAlignment = childrenAlignments.containsKey(child) ? childrenAlignments.get(child) : null; + Alignment childAlignment = childrenAlignmentStrategy.getAlignment(child); blocks.add(buildSubBlock(child, childAlignment)); } return Collections.unmodifiableList(blocks); @@ -219,8 +219,7 @@ public class JetBlock extends AbstractBlock { return myNode.getFirstChildNode() == null; } - @NotNull - protected Map createChildrenAlignments() { + private ASTAlignmentStrategy getChildrenAlignmentStrategy() { CommonCodeStyleSettings jetCommonSettings = mySettings.getCommonSettings(JetLanguage.INSTANCE); // Prepare default null strategy @@ -238,26 +237,7 @@ public class JetBlock extends AbstractBlock { jetCommonSettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS, VALUE_ARGUMENT, COMMA, jetCommonSettings.ALIGN_MULTILINE_METHOD_BRACKETS, LPAR, RPAR); } - - // Construct information about children alignment - HashMap result = new HashMap(); - - for (ASTNode child = myNode.getFirstChildNode(); child != null; child = child.getTreeNext()) { - IElementType childType = child.getElementType(); - - if (child.getTextRange().getLength() == 0) continue; - - if (childType == TokenType.WHITE_SPACE) { - continue; - } - - Alignment childAlignment = strategy.getAlignment(child); - if (childAlignment != null) { - result.put(child, childAlignment); - } - } - - return result; + return strategy; } private static ASTAlignmentStrategy getAlignmentForChildInParenthesis(