[formatter-core] minor refactoring

This commit is contained in:
Yaroslav Lepenkin
2016-06-17 19:35:37 +03:00
parent cb78667a0b
commit d767bd7426
2 changed files with 34 additions and 35 deletions
@@ -52,7 +52,7 @@ public class InitialInfoBuilder {
private final CommonCodeStyleSettings.IndentOptions myOptions;
private final Stack<FormatterBuilderState> myStates = new Stack<>();
private final Stack<InitialInfoBuilderState> myStates = new Stack<>();
private WhiteSpace myCurrentWhiteSpace;
private CompositeBlockWrapper myRootBlockWrapper;
@@ -137,7 +137,7 @@ public class InitialInfoBuilder {
return true;
}
FormatterBuilderState state = myStates.peek();
InitialInfoBuilderState state = myStates.peek();
doIteration(state);
return myStates.isEmpty();
}
@@ -250,11 +250,11 @@ public class InitialInfoBuilder {
return extended;
}
private CompositeBlockWrapper buildCompositeBlock(final Block rootBlock,
@Nullable final CompositeBlockWrapper parent,
final int index,
@Nullable final WrapImpl currentWrapParent,
boolean rootBlockIsRightBlock)
private CompositeBlockWrapper buildCompositeBlock(Block rootBlock,
@Nullable CompositeBlockWrapper parent,
int index,
@Nullable WrapImpl currentWrapParent,
boolean rootBlockIsRightBlock)
{
final CompositeBlockWrapper wrappedRootBlock = new CompositeBlockWrapper(rootBlock, myCurrentWhiteSpace, parent);
if (index == 0) {
@@ -274,21 +274,14 @@ public class InitialInfoBuilder {
final boolean blocksAreReadOnly = rootBlock instanceof ReadOnlyBlockContainer || blocksMayBeOfInterest;
FormatterBuilderState
state = new FormatterBuilderState(rootBlock, wrappedRootBlock, currentWrapParent, blocksAreReadOnly, rootBlockIsRightBlock);
InitialInfoBuilderState state = new InitialInfoBuilderState(
rootBlock, wrappedRootBlock, currentWrapParent, blocksAreReadOnly, rootBlockIsRightBlock);
myStates.push(state);
return wrappedRootBlock;
}
public MultiMap<ExpandableIndent, AbstractBlockWrapper> getExpandableIndentsBlocks() {
return myBlocksToForceChildrenIndent;
}
public MultiMap<Alignment, Block> getBlocksToAlign() {
return myBlocksToAlign;
}
private void doIteration(@NotNull FormatterBuilderState state) {
private void doIteration(@NotNull InitialInfoBuilderState state) {
Block currentRoot = state.parentBlock;
List<Block> subBlocks = currentRoot.getSubBlocks();
@@ -335,15 +328,7 @@ public class InitialInfoBuilder {
myBlocksToForceChildrenIndent.putValue(indent, wrapper);
}
}
public static void setDefaultIndents(final List<AbstractBlockWrapper> list, boolean useRelativeIndents) {
for (AbstractBlockWrapper wrapper : list) {
if (wrapper.getIndent() == null) {
wrapper.setIndent((IndentImpl)Indent.getContinuationWithoutFirstIndent(useRelativeIndents));
}
}
}
private AbstractBlockWrapper processSimpleBlock(final Block rootBlock,
@Nullable final CompositeBlockWrapper parent,
final boolean readOnly,
@@ -475,6 +460,14 @@ public class InitialInfoBuilder {
return myAlignmentsInsideRangeToModify;
}
public MultiMap<ExpandableIndent, AbstractBlockWrapper> getExpandableIndentsBlocks() {
return myBlocksToForceChildrenIndent;
}
public MultiMap<Alignment, Block> getBlocksToAlign() {
return myBlocksToAlign;
}
public void setCollectAlignmentsInsideFormattingRange(boolean value) {
myCollectAlignmentsInsideFormattingRange = value;
}
@@ -22,9 +22,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
import static com.intellij.formatting.InitialInfoBuilder.setDefaultIndents;
class FormatterBuilderState {
class InitialInfoBuilderState {
public final Block parentBlock;
public final WrapImpl parentBlockWrap;
public final CompositeBlockWrapper wrappedBlock;
@@ -35,11 +33,11 @@ class FormatterBuilderState {
private final List<AbstractBlockWrapper> myWrappedChildren = ContainerUtil.newArrayList();
FormatterBuilderState(@NotNull Block parentBlock,
@NotNull CompositeBlockWrapper wrappedBlock,
@Nullable WrapImpl parentBlockWrap,
boolean readOnly,
boolean parentBlockIsRightBlock) {
InitialInfoBuilderState(@NotNull Block parentBlock,
@NotNull CompositeBlockWrapper wrappedBlock,
@Nullable WrapImpl parentBlockWrap,
boolean readOnly,
boolean parentBlockIsRightBlock) {
this.parentBlock = parentBlock;
this.wrappedBlock = wrappedBlock;
this.parentBlockWrap = parentBlockWrap;
@@ -72,5 +70,13 @@ class FormatterBuilderState {
public boolean isProcessed() {
return myWrappedChildren.size() == parentBlock.getSubBlocks().size();
}
private static void setDefaultIndents(final List<AbstractBlockWrapper> list, boolean useRelativeIndents) {
for (AbstractBlockWrapper wrapper : list) {
if (wrapper.getIndent() == null) {
wrapper.setIndent((IndentImpl)Indent.getContinuationWithoutFirstIndent(useRelativeIndents));
}
}
}
}