alignment = myAlignmentMap.get(myNode); } else { alignment = Alignment.createAlignment(true, Alignment.Anchor.LEFT); myAlignmentMap.put(myNode, alignment); alignment = myAlignmentMap.get(myNode); } else { alignment = Alignment.createAlignment(true, Alignment.Anchor.LEFT); myAlignmentMap.put(myNode, alignment); alignment = myAlignmentMap.get(myNode); } else { alignment = Alignment.createAlignment(true, Alignment.Anchor.LEFT); myAlignmentMap.put(myNode, alignment); alignment = myAlignmentMap.get(treeParent); } else { alignment = Alignment.createAlignment(true, Alignment.Anchor.LEFT); myAlignmentMap.put(treeParent, alignment); alignment = Alignment.createAlignment(true, Alignment.Anchor.LEFT); myAlignmentMap.put(myNode, alignment); } else if (childElementType == BallerinaTypes.COLON && parentElementType == BallerinaTypes.TERNARY_EXPRESSION) { alignment = myAlignmentMap.get(treeParent); } else { alignment = Alignment.createAlignment(true, Alignment.Anchor.LEFT); myAlignmentMap.put(treeParent, alignment);
childrenAlignment = Alignment.createChildAlignment(parentAlignment);
@NotNull private List<com.intellij.formatting.Block> buildTypeOperationChildren(@NotNull ASTNode typeOperation) { final Alignment[] operandAlignment = {null}; return buildChildren( typeOperation, (child, childElementType, blockList) -> { if (childElementType == ACCESS_EXPRESSION) { blockList.addAll(buildAccessExpressionChildren(child, operandAlignment[0])); } else if (childElementType == TYPE_INFIX_OPERATOR) { blockList.addAll(buildOperatorRuleChildren(child)); if (codeStyleSettings(typeOperation).ALIGN_TYPE_DEFINITION_TO_RIGHT_OF_OPERATOR) { operandAlignment[0] = Alignment.createAlignment(); } } else { blockList.add(buildChild(child, operandAlignment[0])); } return blockList; } ); }
@NotNull private List<com.intellij.formatting.Block> buildAlignedOperandsOperationChildren( @NotNull ASTNode operation, @NotNull Predicate<CodeStyleSettings> alignOperands, @NotNull TokenSet operatorRuleTokenSet) { Alignment operandAlignment; if (alignOperands.apply(codeStyleSettings(operation))) { operandAlignment = Alignment.createAlignment(); } else { operandAlignment = null; } return buildChildren( operation, (child, childElementType, blockList) -> { if (childElementType == ACCESS_EXPRESSION) { blockList.addAll(buildAccessExpressionChildren(child, operandAlignment)); } else if (operatorRuleTokenSet.contains(childElementType)) { blockList.addAll(buildOperatorRuleChildren(child, null, null, operandAlignment)); } else { blockList.add(buildChild(child, operandAlignment)); } return blockList; } ); }
@NotNull private List<com.intellij.formatting.Block> buildWhenOperationChildren(@NotNull ASTNode whenOperation) { Wrap operatorWrap = Wrap.createWrap(WrapType.NORMAL, true); final Alignment[] operandAlignment = {null}; final Wrap[] operandWrap = {Wrap.createWrap(WrapType.NONE, false)}; return buildChildren( whenOperation, (child, childElementType, blockList) -> { if (childElementType == ACCESS_EXPRESSION) { blockList.addAll( buildAccessExpressionChildren(child, operandWrap[0], operandAlignment[0]) ); } else if (OPERATOR_RULE_TOKEN_SET.contains(childElementType)) { blockList.addAll(buildOperatorRuleChildren(child, operatorWrap)); operandAlignment[0] = Alignment.createAlignment(); operandWrap[0] = Wrap.createChildWrap(operatorWrap, WrapType.NORMAL, true); } else { blockList.add(buildChild(child, operandWrap[0], operandAlignment[0])); } return blockList; } ); }
Alignment childAlignment = Alignment.createAlignment();
private List<com.intellij.formatting.Block> buildMultipleAliasesChildren(@NotNull ASTNode multipleAliases) { Alignment aliasAlignment = Alignment.createAlignment();
nestedStartAlignment = Alignment.createAlignment(); } else { nestedStartAlignment = startAlignment; operandAlignment[0] = Alignment.createAlignment(); operandWrap[0] = Wrap.createWrap(WrapType.NONE, true); } else {
@NotNull @Override public ChildAttributes getChildAttributes(int newChildIndex) { ChildAttributes childAttributes; if (newChildIndex > 0) { childAttributes = DELEGATE_TO_PREV_CHILD; } else if (myNode.getElementType() == DO) { boolean indentRelativeToDirectParent = codeStyleSettings(myNode).ALIGN_UNMATCHED_CALL_DO_BLOCKS == CodeStyleSettings.UnmatchedCallDoBlockAlignment.CALL.value; Indent indent = Indent.getNormalIndent(indentRelativeToDirectParent); childAttributes = new ChildAttributes( indent, /* all children share the same alignment as expressions inside a doBlock above the stab are assumed to be aligned on the left-side */ Alignment.createAlignment() ); } else { childAttributes = super.getChildAttributes(newChildIndex); } return childAttributes; }
@NotNull private List<Block> buildSubBlocks() { AlignmentStrategy.AlignmentPerTypeStrategy strategy = null; boolean isStruct = getNode().getElementType() == STRUCT_TYPE; Alignment forType = null; if (isStruct) { strategy = AlignmentStrategy.createAlignmentPerTypeStrategy(ContainerUtil.list(FIELD_DECLARATION, LINE_COMMENT), STRUCT_TYPE, true); forType = Alignment.createAlignment(true); } List<Block> blocks = ContainerUtil.newArrayList(); 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; IElementType substitutor = childType == MULTILINE_COMMENT ? LINE_COMMENT : childType; Alignment alignment = strategy != null ? strategy.getAlignment(substitutor) : null; GoFormattingBlock e = buildSubBlock(child, alignment); if (isStruct) { e.putUserDataIfAbsent(TYPE_ALIGNMENT_INSIDE_STRUCT, forType); } blocks.add(e); } return Collections.unmodifiableList(blocks); }
child, stabBodyChildrenWrap, Alignment.createAlignment(), childrenIndent
ParentBlock(@NotNull ASTNode node, @Nullable Alignment alignment, Indent indent, CodeStyleSettings settings) { super(node, alignment, indent, settings); childAlignment = Alignment.createAlignment(); }
@NotNull public Alignment getAssignAlignment(@NotNull ASTNode defaultDirectiveNode) { Alignment result = myAssignAlignmentMap.get(defaultDirectiveNode); if (result != null) { return result; } result = Alignment.createAlignment(true); myAssignAlignmentMap.put(defaultDirectiveNode, result); return result; } }
@Override public Alignment getAlignment(@NotNull final ASTNode currentNode) { Validate.notNull(currentNode); final Alignment alignment; if (isNewColumn(currentNode)) { if (columnNumber >= alignments.size()) { alignment = Alignment.createAlignment(true, Alignment.Anchor.LEFT); alignments.add(alignment); } else { alignment = alignments.get(columnNumber); } columnNumber++; } else { alignment = Alignment.createAlignment(); } return alignment; }
protected CsvBlock(@NotNull ASTNode node, CsvFormattingInfo formattingInfo) { super(node, Wrap.createWrap(WrapType.NONE, false), Alignment.createAlignment()); this.myFormattingInfo = formattingInfo; }
@NotNull public ChildAttributes getChildAttributes(int newChildIndex) { return new ChildAttributes(Indent.getNoneIndent(), Alignment.createAlignment()); //return ChildAttributes.DELEGATE_TO_NEXT_CHILD; }
/** * Returns line-based alignment for the {@code childNode}. Uses previous line alignment from the {@code alignmentsMap} * or creates a new one. * * @param alignmentsMap map for caching line-based values */ @Nullable private Alignment getLineBasedAlignment(@NotNull ASTNode childNode, @NotNull Map<Integer, Alignment> alignmentsMap) { int nodeLine = getNodeLine(childNode); if (nodeLine < 0) { return null; } Alignment alignment = alignmentsMap.get(nodeLine); if (alignment != null) { return alignment; } alignment = alignmentsMap.get(nodeLine - 1); if (alignment == null) { alignment = alignmentsMap.get(nodeLine + 1); } if (alignment == null) { alignment = Alignment.createAlignment(true); } alignmentsMap.put(nodeLine, alignment); return alignment; }
private void appendProtoBlocks(ASTNode protoRootNode, List<Block> blocks) { ASTNode child = protoRootNode.getFirstChildNode(); Alignment alignment = Alignment.createAlignment(); while (child != null) { if (!FormatterUtil.containsWhiteSpacesOnly(child)) { Block block = createBlock(child, alignment, Indent.getNoneIndent(), settings); blocks.add(block); } child = child.getTreeNext(); } }
@Override protected List<Block> buildChildren() { ASTNode child = getNode().getFirstChildNode(); List<Block> result = new ArrayList<>(); while (child != null) { if (!FormatterUtil.containsWhiteSpacesOnly(child)) { Block block = BlockFactory.createBlock(child, Alignment.createAlignment(), Indent.getNoneIndent(), settings); result.add(block); } child = child.getTreeNext(); } return result; }
@NotNull @Override public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) { final Block impexBlock = new ImpexBlock( element.getNode(), null, Alignment.createAlignment(), createSpaceBuilder(settings), settings ); return FormattingModelProvider.createFormattingModelForPsiFile( element.getContainingFile(), impexBlock, settings ); }