diff --git a/java/java-impl/src/com/intellij/psi/formatter/java/AbstractJavaBlock.java b/java/java-impl/src/com/intellij/psi/formatter/java/AbstractJavaBlock.java index 313718928ef4..8ec93c2f3fcc 100644 --- a/java/java-impl/src/com/intellij/psi/formatter/java/AbstractJavaBlock.java +++ b/java/java-impl/src/com/intellij/psi/formatter/java/AbstractJavaBlock.java @@ -709,33 +709,6 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo return new ChainMethodCallsBlockBuilder(alignment, blockWrap, indent).build(nodes); } - @NotNull - private Block createSyntheticBlock(@NotNull final List subNodes, final Wrap wrap, @Nullable final Alignment alignment) { - final ArrayList subBlocks = new ArrayList(); - final ASTNode firstNode = subNodes.get(0); - if (firstNode.getElementType() == JavaTokenType.DOT) { - subBlocks.add(createJavaBlock(firstNode, getSettings(), myJavaSettings, Indent.getNoneIndent(), null, AlignmentStrategy.getNullStrategy())); - subNodes.remove(0); - if (!subNodes.isEmpty()) { - subBlocks.add(createSyntheticBlock(subNodes, wrap, null)); - } - return new SyntheticCodeBlock(subBlocks, alignment, mySettings, - myJavaSettings, Indent.getContinuationIndent(myIndentSettings.USE_RELATIVE_INDENTS), wrap); - } - return new SyntheticCodeBlock(createJavaBlocks(subNodes), alignment, mySettings, - myJavaSettings, Indent.getContinuationWithoutFirstIndent(myIndentSettings.USE_RELATIVE_INDENTS), null); - } - - @NotNull - private List createJavaBlocks(@NotNull final List subNodes) { - final ArrayList result = new ArrayList(); - for (ASTNode node : subNodes) { - result.add(createJavaBlock(node, getSettings(), myJavaSettings, Indent.getContinuationWithoutFirstIndent(myIndentSettings.USE_RELATIVE_INDENTS), null, - AlignmentStrategy.getNullStrategy())); - } - return result; - } - private static void collectNodes(@NotNull List nodes, @NotNull ASTNode node) { ASTNode child = node.getFirstChildNode(); while (child != null) { @@ -1384,7 +1357,8 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo myWrap = getNewWrap(); } - blocks.add(createSyntheticBlock(currentCallChunk.nodes, wrapToUse, alignmentToUse)); + SyntheticBlockBuilder builder = new SyntheticBlockBuilder(mySettings, myJavaSettings); + blocks.add(builder.create(currentCallChunk.nodes, wrapToUse, alignmentToUse)); } return blocks; diff --git a/java/java-impl/src/com/intellij/psi/formatter/java/SyntheticBlockBuilder.java b/java/java-impl/src/com/intellij/psi/formatter/java/SyntheticBlockBuilder.java new file mode 100644 index 000000000000..bd5a262ecb01 --- /dev/null +++ b/java/java-impl/src/com/intellij/psi/formatter/java/SyntheticBlockBuilder.java @@ -0,0 +1,75 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.psi.formatter.java; + +import com.intellij.formatting.Alignment; +import com.intellij.formatting.Block; +import com.intellij.formatting.Indent; +import com.intellij.formatting.Wrap; +import com.intellij.formatting.alignment.AlignmentStrategy; +import com.intellij.lang.ASTNode; +import com.intellij.psi.JavaTokenType; +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; +import com.intellij.psi.codeStyle.JavaCodeStyleSettings; +import com.intellij.psi.formatter.java.SyntheticCodeBlock; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import static com.intellij.psi.formatter.java.AbstractJavaBlock.*; + +public class SyntheticBlockBuilder { + + private final CommonCodeStyleSettings mySettings; + private final CommonCodeStyleSettings.IndentOptions myIndentSettings; + private final JavaCodeStyleSettings myJavaSettings; + + public SyntheticBlockBuilder(@NotNull CommonCodeStyleSettings settings, @NotNull JavaCodeStyleSettings javaSettings) { + mySettings = settings; + myIndentSettings = settings.getIndentOptions(); + myJavaSettings = javaSettings; + } + + @NotNull + public Block create(@NotNull final List subNodes, final Wrap wrap, @Nullable final Alignment alignment) { + final ArrayList subBlocks = new ArrayList(); + final ASTNode firstNode = subNodes.get(0); + if (firstNode.getElementType() == JavaTokenType.DOT) { + AlignmentStrategy strategy = AlignmentStrategy.getNullStrategy(); + Block block = createJavaBlock(firstNode, mySettings, myJavaSettings, Indent.getNoneIndent(), null, strategy); + subBlocks.add(block); + subNodes.remove(0); + if (!subNodes.isEmpty()) { + subBlocks.add(create(subNodes, wrap, null)); + } + return new SyntheticCodeBlock(subBlocks, alignment, mySettings, myJavaSettings, Indent.getContinuationIndent(myIndentSettings.USE_RELATIVE_INDENTS), wrap); + } + return new SyntheticCodeBlock(createJavaBlocks(subNodes), alignment, mySettings, myJavaSettings, Indent.getContinuationWithoutFirstIndent(myIndentSettings.USE_RELATIVE_INDENTS), null); + } + + @NotNull + private List createJavaBlocks(@NotNull final List subNodes) { + final ArrayList result = new ArrayList(); + for (ASTNode node : subNodes) { + Indent indent = Indent.getContinuationWithoutFirstIndent(myIndentSettings.USE_RELATIVE_INDENTS); + result.add(createJavaBlock(node, mySettings, myJavaSettings, indent, null, AlignmentStrategy.getNullStrategy())); + } + return result; + } + +} \ No newline at end of file