refactoring AbstractJavaBlock, make createJavaBlock non static

This commit is contained in:
Yaroslav Lepenkin
2015-06-15 15:02:40 +03:00
parent 08c21bf96f
commit 77a8d4cee3
3 changed files with 52 additions and 26 deletions
@@ -54,7 +54,7 @@ public class JavaFormattingModelBuilder implements FormattingModelBuilder {
LOG.assertTrue(fileElement != null, "File element should not be null for " + element);
CommonCodeStyleSettings commonSettings = settings.getCommonSettings(JavaLanguage.INSTANCE);
JavaCodeStyleSettings customJavaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
Block block = AbstractJavaBlock.createJavaBlock(fileElement, commonSettings, customJavaSettings);
Block block = AbstractJavaBlock.newJavaBlock(fileElement, commonSettings, customJavaSettings);
FormattingDocumentModelImpl model = FormattingDocumentModelImpl.createOn(element.getContainingFile());
return new PsiBasedFormatterModelWithShiftIndentInside (element.getContainingFile(), block, model);
}
@@ -89,6 +89,18 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
this(node, wrap, indent, settings, javaSettings, JavaWrapManager.INSTANCE, alignmentStrategy);
}
private AbstractJavaBlock(@NotNull ASTNode ignored,
@NotNull CommonCodeStyleSettings commonSettings,
@NotNull JavaCodeStyleSettings javaSettings) {
super(ignored, null, null);
mySettings = commonSettings;
myJavaSettings = javaSettings;
myIndentSettings = commonSettings.getIndentOptions();
myIndent = null;
myWrapManager = JavaWrapManager.INSTANCE;
myAlignmentStrategy = AlignmentStrategy.getNullStrategy();
}
protected AbstractJavaBlock(@NotNull final ASTNode node,
final Wrap wrap,
final Indent indent,
@@ -116,33 +128,33 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
}
@NotNull
public static Block createJavaBlock(@NotNull ASTNode child,
@NotNull CommonCodeStyleSettings settings,
@NotNull JavaCodeStyleSettings javaSettings,
@Nullable Indent indent,
@Nullable Wrap wrap,
Alignment alignment) {
public Block createJavaBlock(@NotNull ASTNode child,
@NotNull CommonCodeStyleSettings settings,
@NotNull JavaCodeStyleSettings javaSettings,
@Nullable Indent indent,
@Nullable Wrap wrap,
Alignment alignment) {
return createJavaBlock(child, settings, javaSettings,indent, wrap, AlignmentStrategy.wrap(alignment));
}
@NotNull
public static Block createJavaBlock(@NotNull ASTNode child,
@NotNull CommonCodeStyleSettings settings,
@NotNull JavaCodeStyleSettings javaSettings,
final Indent indent,
@Nullable Wrap wrap,
@NotNull AlignmentStrategy alignmentStrategy) {
public Block createJavaBlock(@NotNull ASTNode child,
@NotNull CommonCodeStyleSettings settings,
@NotNull JavaCodeStyleSettings javaSettings,
final Indent indent,
@Nullable Wrap wrap,
@NotNull AlignmentStrategy alignmentStrategy) {
return createJavaBlock(child, settings, javaSettings, indent, wrap, alignmentStrategy, -1);
}
@NotNull
private static Block createJavaBlock(@NotNull ASTNode child,
@NotNull CommonCodeStyleSettings settings,
@NotNull JavaCodeStyleSettings javaSettings,
@Nullable Indent indent,
Wrap wrap,
@NotNull AlignmentStrategy alignmentStrategy,
int startOffset) {
private Block createJavaBlock(@NotNull ASTNode child,
@NotNull CommonCodeStyleSettings settings,
@NotNull JavaCodeStyleSettings javaSettings,
@Nullable Indent indent,
Wrap wrap,
@NotNull AlignmentStrategy alignmentStrategy,
int startOffset) {
Indent actualIndent = indent == null ? getDefaultSubtreeIndent(child, getJavaIndentOptions(settings)) : indent;
final IElementType elementType = child.getElementType();
Alignment alignment = alignmentStrategy.getAlignment(elementType);
@@ -194,12 +206,26 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
}
@NotNull
public static Block createJavaBlock(@NotNull ASTNode child,
public static Block newJavaBlock(@NotNull ASTNode child,
@NotNull CommonCodeStyleSettings settings,
@NotNull JavaCodeStyleSettings javaSettings) {
return createJavaBlock(
child, settings, javaSettings, getDefaultSubtreeIndent(child, getJavaIndentOptions(settings)), null, AlignmentStrategy.getNullStrategy()
);
final Indent indent = getDefaultSubtreeIndent(child, getJavaIndentOptions(settings));
return newJavaBlock(child, settings, javaSettings, indent, null, AlignmentStrategy.getNullStrategy());
}
@NotNull
public static Block newJavaBlock(@NotNull ASTNode child,
@NotNull CommonCodeStyleSettings settings,
@NotNull JavaCodeStyleSettings javaSettings,
@Nullable Indent indent,
@Nullable Wrap wrap,
@NotNull AlignmentStrategy strategy) {
return new AbstractJavaBlock(child, settings, javaSettings) {
@Override
protected List<Block> buildChildren() {
return null;
}
}.createJavaBlock(child, settings, javaSettings, indent, wrap, strategy);
}
@NotNull
@@ -51,7 +51,7 @@ public class SyntheticBlockBuilder {
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);
Block block = newJavaBlock(firstNode, mySettings, myJavaSettings, Indent.getNoneIndent(), null, strategy);
subBlocks.add(block);
subNodes.remove(0);
if (!subNodes.isEmpty()) {
@@ -67,7 +67,7 @@ public class SyntheticBlockBuilder {
final ArrayList<Block> result = new ArrayList<Block>();
for (ASTNode node : subNodes) {
Indent indent = Indent.getContinuationWithoutFirstIndent(myIndentSettings.USE_RELATIVE_INDENTS);
result.add(createJavaBlock(node, mySettings, myJavaSettings, indent, null, AlignmentStrategy.getNullStrategy()));
result.add(newJavaBlock(node, mySettings, myJavaSettings, indent, null, AlignmentStrategy.getNullStrategy()));
}
return result;
}