use of com.intellij.formatting.Alignment in project buck by facebook.
the class BuckBlock method buildSubBlock.
private BuckBlock buildSubBlock(ASTNode childNode) {
Indent indent = Indent.getNoneIndent();
Alignment alignment = null;
Wrap wrap = null;
if (hasElementType(myNode, BUCK_CONTAINERS)) {
if (hasElementType(childNode, BuckTypes.COMMA)) {
wrap = Wrap.createWrap(WrapType.NONE, true);
} else if (!hasElementType(childNode, BUCK_ALL_BRACES)) {
assert myChildWrap != null;
wrap = myChildWrap;
indent = Indent.getNormalIndent();
}
}
return new BuckBlock(childNode, mySettings, alignment, indent, wrap);
}
use of com.intellij.formatting.Alignment in project intellij-community by JetBrains.
the class ExtendsListBlock method buildChildren.
@Override
protected List<Block> buildChildren() {
final ArrayList<Block> result = new ArrayList<>();
ArrayList<Block> elementsExceptKeyword = new ArrayList<>();
myChildAlignment = createChildAlignment();
myChildIndent = Indent.getContinuationIndent(myIndentSettings.USE_RELATIVE_INDENTS);
myUseChildAttributes = true;
Wrap childWrap = createChildWrap();
ASTNode child = myNode.getFirstChildNode();
Alignment alignment = alignList() ? Alignment.createAlignment() : null;
while (child != null) {
if (!FormatterUtil.containsWhiteSpacesOnly(child) && child.getTextLength() > 0) {
IElementType elementType = child.getElementType();
if (ElementType.KEYWORD_BIT_SET.contains(elementType)) {
if (!elementsExceptKeyword.isEmpty()) {
result.add(new SyntheticCodeBlock(elementsExceptKeyword, null, mySettings, myJavaSettings, Indent.getNoneIndent(), null));
elementsExceptKeyword = new ArrayList<>();
}
Indent indent = mySettings.ALIGN_THROWS_KEYWORD && elementType == JavaTokenType.THROWS_KEYWORD ? Indent.getNoneIndent() : myChildIndent;
result.add(createJavaBlock(child, mySettings, myJavaSettings, indent, arrangeChildWrap(child, childWrap), alignment));
} else {
Alignment candidate = myAlignmentStrategy.getAlignment(elementType);
if (candidate != null) {
alignment = myChildAlignment = candidate;
}
processChild(elementsExceptKeyword, child, myChildAlignment, childWrap, myChildIndent);
}
}
child = child.getTreeNext();
}
if (!elementsExceptKeyword.isEmpty()) {
result.add(new SyntheticCodeBlock(elementsExceptKeyword, alignment, mySettings, myJavaSettings, Indent.getNoneIndent(), null));
}
return result;
}
use of com.intellij.formatting.Alignment in project intellij-community by JetBrains.
the class ArrayInitializerBlocksBuilder method buildBlocks.
public List<Block> buildBlocks() {
Wrap wrap = Wrap.createWrap(getWrapType(mySettings.ARRAY_INITIALIZER_WRAP), false);
Alignment alignment = mySettings.ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION ? Alignment.createAlignment() : null;
ChildrenBlocksBuilder.Config config = new ChildrenBlocksBuilder.Config().setDefaultIndent(Indent.getContinuationWithoutFirstIndent()).setIndent(JavaTokenType.RBRACE, Indent.getNoneIndent()).setIndent(JavaTokenType.LBRACE, Indent.getNoneIndent()).setDefaultWrap(wrap).setNoWrap(JavaTokenType.COMMA).setNoWrap(JavaTokenType.RBRACE).setNoWrap(JavaTokenType.LBRACE).setDefaultAlignment(alignment).setNoAlignment(JavaTokenType.COMMA).setNoAlignment(JavaTokenType.LBRACE).setNoAlignmentIf(JavaTokenType.RBRACE, node -> {
PsiElement prev = PsiTreeUtil.skipSiblingsBackward(node.getPsi(), PsiWhiteSpace.class);
if (prev == null)
return false;
return prev.getNode().getElementType() != JavaTokenType.COMMA;
});
return config.createBuilder().buildNodeChildBlocks(myNode, myBlockFactory);
}
use of com.intellij.formatting.Alignment in project intellij-community by JetBrains.
the class ChainedCallChunk method buildBlocksFrom.
private List<Block> buildBlocksFrom(List<ASTNode> nodes) {
List<ChainedCallChunk> methodCall = splitMethodCallOnChunksByDots(nodes);
Wrap wrap = null;
Alignment chainedCallsAlignment = null;
List<Block> blocks = new ArrayList<>();
for (int i = 0; i < methodCall.size(); i++) {
ChainedCallChunk currentCallChunk = methodCall.get(i);
if (isMethodCall(currentCallChunk) || isComment(currentCallChunk)) {
if (wrap == null) {
wrap = createCallChunkWrap(i, methodCall);
}
if (chainedCallsAlignment == null) {
chainedCallsAlignment = createCallChunkAlignment(i, methodCall);
}
} else {
wrap = null;
chainedCallsAlignment = null;
}
CallChunkBlockBuilder builder = new CallChunkBlockBuilder(mySettings, myJavaSettings);
blocks.add(builder.create(currentCallChunk.nodes, wrap, chainedCallsAlignment));
}
return blocks;
}
use of com.intellij.formatting.Alignment in project intellij-community by JetBrains.
the class AnnotationInitializerBlocksBuilder method buildBlocks.
public List<Block> buildBlocks() {
final Wrap wrap = Wrap.createWrap(getWrapType(myJavaSettings.ANNOTATION_PARAMETER_WRAP), false);
final Alignment alignment = myJavaSettings.ALIGN_MULTILINE_ANNOTATION_PARAMETERS ? Alignment.createAlignment() : null;
ChildrenBlocksBuilder.Config config = new ChildrenBlocksBuilder.Config().setDefaultIndent(Indent.getContinuationWithoutFirstIndent()).setIndent(JavaTokenType.RPARENTH, Indent.getNoneIndent()).setIndent(JavaTokenType.LPARENTH, Indent.getNoneIndent()).setDefaultWrap(wrap).setNoWrap(JavaTokenType.COMMA).setNoWrap(JavaTokenType.RPARENTH).setNoWrap(JavaTokenType.LPARENTH).setDefaultAlignment(alignment).setNoAlignment(JavaTokenType.COMMA).setNoAlignment(JavaTokenType.LPARENTH).setNoAlignmentIf(JavaTokenType.RPARENTH, node -> {
PsiElement prev = PsiTreeUtil.skipSiblingsBackward(node.getPsi(), PsiWhiteSpace.class);
if (prev == null)
return false;
return prev instanceof PsiNameValuePair && !PsiTreeUtil.hasErrorElements(prev);
});
return config.createBuilder().buildNodeChildBlocks(myNode, myFactory);
}
Aggregations