Refactoring: build subblocks of JetBlock in one pass

This commit is contained in:
Andrey Ponomarev
2013-02-20 16:42:24 +01:00
committed by Nikolay Krasko
parent 7245b05426
commit 6a7e72bfc5
@@ -79,7 +79,7 @@ public class JetBlock extends AbstractBlock {
private List<Block> buildSubBlocks() { private List<Block> buildSubBlocks() {
List<Block> blocks = new ArrayList<Block>(); List<Block> blocks = new ArrayList<Block>();
Map<ASTNode, Alignment> childrenAlignments = createChildrenAlignments(); ASTAlignmentStrategy childrenAlignmentStrategy = getChildrenAlignmentStrategy();
for (ASTNode child = myNode.getFirstChildNode(); child != null; child = child.getTreeNext()) { for (ASTNode child = myNode.getFirstChildNode(); child != null; child = child.getTreeNext()) {
IElementType childType = child.getElementType(); IElementType childType = child.getElementType();
@@ -90,7 +90,7 @@ public class JetBlock extends AbstractBlock {
continue; continue;
} }
Alignment childAlignment = childrenAlignments.containsKey(child) ? childrenAlignments.get(child) : null; Alignment childAlignment = childrenAlignmentStrategy.getAlignment(child);
blocks.add(buildSubBlock(child, childAlignment)); blocks.add(buildSubBlock(child, childAlignment));
} }
return Collections.unmodifiableList(blocks); return Collections.unmodifiableList(blocks);
@@ -219,8 +219,7 @@ public class JetBlock extends AbstractBlock {
return myNode.getFirstChildNode() == null; return myNode.getFirstChildNode() == null;
} }
@NotNull private ASTAlignmentStrategy getChildrenAlignmentStrategy() {
protected Map<ASTNode, Alignment> createChildrenAlignments() {
CommonCodeStyleSettings jetCommonSettings = mySettings.getCommonSettings(JetLanguage.INSTANCE); CommonCodeStyleSettings jetCommonSettings = mySettings.getCommonSettings(JetLanguage.INSTANCE);
// Prepare default null strategy // 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_PARAMETERS_IN_CALLS, VALUE_ARGUMENT, COMMA,
jetCommonSettings.ALIGN_MULTILINE_METHOD_BRACKETS, LPAR, RPAR); jetCommonSettings.ALIGN_MULTILINE_METHOD_BRACKETS, LPAR, RPAR);
} }
return strategy;
// Construct information about children alignment
HashMap<ASTNode, Alignment> result = new HashMap<ASTNode, Alignment>();
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;
} }
private static ASTAlignmentStrategy getAlignmentForChildInParenthesis( private static ASTAlignmentStrategy getAlignmentForChildInParenthesis(