private Indent indentOfMultipleDeclarationChild(@NotNull IElementType childType, @NotNull IElementType specType) { if (childType == specType) { return Indent.getNormalIndent(); } return COMMENTS.contains(childType) && myNode.findChildByType(specType) != null ? Indent.getNormalIndent() : Indent.getNoneIndent(); }
@NotNull private static Indent indentIfNotBrace(@NotNull ASTNode child) { return BRACES_TOKEN_SET.contains(child.getElementType()) ? Indent.getNoneIndent() : Indent.getNormalIndent(); }
return Indent.getNormalIndent(); } else if (parentElementType == BallerinaTypes.RECORD_LITERAL_BODY) { return Indent.getNormalIndent(); } else if (parentElementType == BallerinaTypes.WAIT_FOR_COLLECTION) { if (childElementType != BallerinaTypes.LEFT_BRACE && childElementType != BallerinaTypes.RIGHT_BRACE) { return Indent.getNormalIndent(); || parentElementType == BallerinaTypes.COMMITTED_CLAUSE || parentElementType == BallerinaTypes.RECORD_TYPE_NAME)) { return Indent.getNormalIndent(); } else if (parentElementType == BallerinaTypes.CALLABLE_UNIT_SIGNATURE) { return Indent.getIndent(Indent.Type.NORMAL, true, true); } else if (childElementType == BallerinaTypes.RETURN_PARAMETER) { return Indent.getNormalIndent(); } else if (childElementType == BallerinaTypes.RETURN_TYPE) { return Indent.getIndent(Indent.Type.NORMAL, true, true); return Indent.getIndent(Indent.Type.NORMAL, true, true); } else if (parentElementType == BallerinaTypes.MATCH_PATTERN_CLAUSE) { return Indent.getNormalIndent(); } else if (childElementType == BallerinaTypes.FIELD_DEFINITION || childElementType == BallerinaTypes.RECORD_REST_FIELD_DEFINITION) { return Indent.getNormalIndent(); } else if (childElementType == BallerinaTypes.SERVICE_BODY_MEMBER && parentElementType == BallerinaTypes.SERVICE_BODY) { return Indent.getNormalIndent(); } else if (childElementType == BallerinaTypes.TYPE_REFERENCE && parentElementType == BallerinaTypes.RECORD_FIELD_DEFINITION_LIST) { return Indent.getNormalIndent();
@NotNull private List<com.intellij.formatting.Block> buildKeywordsChildren(@NotNull ASTNode keywords, @NotNull Wrap keywordPairWrap) { return buildChildren( keywords, (child, childElementType, blockList) -> { if (childElementType == KEYWORD_PAIR) { blockList.add(buildChild(child, keywordPairWrap, Indent.getNormalIndent())); } else { // commas and comments blockList.add(buildChild(child)); } return blockList; } ); }
@NotNull private List<com.intellij.formatting.Block> buildAssociationsBaseChildren( @NotNull ASTNode associationsBase, @NotNull Wrap containerAssociationOperationWrap) { return buildChildren( associationsBase, (child, childElementType, blockList) -> { if (childElementType == CONTAINER_ASSOCIATION_OPERATION) { blockList.add(buildChild(child, containerAssociationOperationWrap, Indent.getNormalIndent())); } else { blockList.add(buildChild(child)); } return blockList; } ); }
@NotNull @Override public ChildAttributes getChildAttributes(int newChildIndex) { Indent childIndent = Indent.getNoneIndent(); IElementType parentType = myNode.getElementType(); if (BLOCKS_TOKEN_SET.contains(parentType) || parentType == IMPORT_DECLARATION || parentType == CONST_DECLARATION || parentType == VAR_DECLARATION || parentType == TYPE_DECLARATION || parentType == ARGUMENT_LIST) { childIndent = Indent.getNormalIndent(); } if (parentType == EXPR_SWITCH_STATEMENT || parentType == TYPE_SWITCH_STATEMENT || parentType == SELECT_STATEMENT) { List<Block> subBlocks = getSubBlocks(); Block block = subBlocks.size() > newChildIndex ? subBlocks.get(newChildIndex - 1) : null; if (block instanceof GoFormattingBlock) { IElementType type = ((GoFormattingBlock)block).getNode().getElementType(); if (type == TYPE_CASE_CLAUSE || type == EXPR_CASE_CLAUSE) { childIndent = Indent.getNormalIndent(); } else if (type == COMM_CLAUSE) { childIndent = Indent.getNormalIndent(true); } } } return new ChildAttributes(childIndent, null); }
@NotNull private List<com.intellij.formatting.Block> buildMapArgumentsChildren(@NotNull ASTNode mapArguments, @Nullable Wrap openingCurlyWrap, @Nullable Indent elementIndent, @Nullable Wrap mapArgumentsWrap, @Nullable Alignment mapArgumentsAlignment) { return buildContainerChildren( mapArguments, OPENING_CURLY, openingCurlyWrap, elementIndent, mapArgumentsWrap, CLOSING_CURLY, mapArgumentsAlignment, (child, childElementType, tailWrap, childrenIndent, blockList) -> { if (childElementType == MAP_CONSTRUCTION_ARGUMENTS) { blockList.addAll(buildMapConstructArgumentsChildren(child, tailWrap)); } else if (childElementType == MAP_UPDATE_ARGUMENTS) { blockList.addAll(buildMapUpdateArgumentsChildren(child, tailWrap)); } else { blockList.add(buildChild(child, tailWrap, Indent.getNormalIndent())); } return blockList; }); }
Indent childIndent = Indent.getNoneIndent(); if (myNode.getElementType() == BallerinaTypes.CALLABLE_UNIT_BODY) { childIndent = Indent.getNormalIndent(); } else if (myNode.getElementType() == BallerinaTypes.WORKER_WITH_STATEMENTS_BLOCK) { childIndent = Indent.getNormalIndent(); } else if (myNode.getElementType() == BallerinaTypes.SERVICE_BODY) { childIndent = Indent.getNormalIndent(); } else if (myNode.getElementType() == BallerinaTypes.RECORD_LITERAL) { childIndent = Indent.getNormalIndent(); } else if (myNode.getElementType() == BallerinaTypes.RECORD_LITERAL_BODY) { childIndent = Indent.getNormalIndent(); } else if (myNode.getElementType() == BallerinaTypes.WORKER_BODY) { childIndent = Indent.getNormalIndent(); } else if (myNode.getElementType() == BallerinaTypes.WHILE_STATEMENT_BODY) { childIndent = Indent.getNormalIndent(); } else if (myNode.getElementType() == BallerinaTypes.FORK_JOIN_STATEMENT) { childIndent = Indent.getNormalIndent(); } else if (myNode.getElementType() == BallerinaTypes.MATCH_STATEMENT_BODY) { childIndent = Indent.getNormalIndent(); } else if (myNode.getElementType() == BallerinaTypes.VAR_MATCH_PATTERN) { childIndent = Indent.getNormalIndent(); } else if (myNode.getElementType() == BallerinaTypes.STATIC_MATCH_PATTERN) { childIndent = Indent.getNormalIndent(); } else if (myNode.getElementType() == BallerinaTypes.FOREACH_STATEMENT) { childIndent = Indent.getNormalIndent(); } else if (myNode.getElementType() == BallerinaTypes.IF_CLAUSE) { childIndent = Indent.getNormalIndent(); } else if (myNode.getElementType() == BallerinaTypes.ELSE_IF_CLAUSE) { childIndent = Indent.getNormalIndent();
@Nullable private Indent stabChildrenIndent(@NotNull ASTNode stab) { Indent childrenIndent; if (firstOnLine(stab)) { ASTNode stabParent = stab.getTreeParent(); childrenIndent = Indent.getNormalIndent( stabParent.getElementType() == DO_BLOCK && codeStyleSettings(stabParent).ALIGN_UNMATCHED_CALL_DO_BLOCKS == CodeStyleSettings.UnmatchedCallDoBlockAlignment.CALL.value ); } else { childrenIndent = null; } return childrenIndent; }
if (childElementType == ACCESS_EXPRESSION) { blockList.addAll(buildAccessExpressionChildren(child, tailWrap, Indent.getNormalIndent())); } else if (childElementType == CLOSING_PARENTHESIS) { blockList.add(buildChild(child, tailWrap, parentAlignment, Indent.getNoneIndent())); } else { blockList.add(buildChild(child, tailWrap, Indent.getNormalIndent()));
@NotNull private Indent calcIndent(@NotNull ASTNode child) { IElementType parentType = myNode.getElementType(); IElementType type = child.getElementType(); if (type == SWITCH_START) return Indent.getNoneIndent(); if (parentType == BLOCK && type == SELECT_STATEMENT) return Indent.getNoneIndent(); if (parentType == SELECT_STATEMENT && type == RBRACE) return Indent.getNormalIndent(); if (parentType == ARGUMENT_LIST && type != LPAREN && type != RPAREN) return Indent.getNormalIndent(); if ((parentType == EXPR_CASE_CLAUSE || parentType == TYPE_CASE_CLAUSE) && (type == CASE || type == DEFAULT)) return Indent.getNoneIndent(); if (BLOCKS_TOKEN_SET.contains(parentType)) return indentIfNotBrace(child); if (parentType == IMPORT_DECLARATION) return indentOfMultipleDeclarationChild(type, IMPORT_SPEC); if (parentType == CONST_DECLARATION) return indentOfMultipleDeclarationChild(type, CONST_SPEC); if (parentType == VAR_DECLARATION) return indentOfMultipleDeclarationChild(type, VAR_SPEC); if (parentType == TYPE_DECLARATION) return indentOfMultipleDeclarationChild(type, TYPE_SPEC); if (parentType == COMM_CLAUSE && child.getPsi() instanceof GoStatement) return Indent.getNormalIndent(); if (child.getPsi() instanceof GoExpression) return Indent.getContinuationWithoutFirstIndent(); return Indent.getNoneIndent(); }
@Nullable Alignment endAlignment) { boolean relativeToIndirectParent = !firstOnLine(anonymousFunction) && !lastArgument(anonymousFunction); Indent stabIndent = Indent.getNormalIndent(relativeToIndirectParent);
@NotNull private List<com.intellij.formatting.Block> buildParentheticalStabChildren(@NotNull ASTNode parentheticalStab) { Indent childIndent = Indent.getNormalIndent(); Wrap stabBodyChildrenWrap; if (parentheticalStab.textContains('\n')) { stabBodyChildrenWrap = null; } else { stabBodyChildrenWrap = Wrap.createWrap(WrapType.CHOP_DOWN_IF_LONG, true); } return buildChildren( parentheticalStab, (child, childElementType, blockList) -> { if (childElementType == SEMICOLON) { blockList.add( buildChild(child, Wrap.createWrap(WrapType.NONE, true), childIndent) ); } else if (childElementType == STAB) { blockList.addAll(buildStabChildren((CompositeElement) child, stabBodyChildrenWrap)); } else { blockList.add(buildChild(child)); } return blockList; } ); }
openingWrap, containerValueWrap(child), Indent.getNormalIndent(true), null openingWrap, listContainerValueWrap(child), Indent.getNormalIndent(true), null openingWrap, mapContainerValueWrap(openingWrap, child), Indent.getNormalIndent(true), null openingWrap, containerValueWrap(child), Indent.getNormalIndent(true), null
@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; }
} else if (childElementType == END_OF_EXPRESSION) { blockList.addAll( buildEndOfExpressionChildren(child, null, Indent.getNormalIndent()) ); } else if (childElementType == STAB) {
IElementType stabParentElementType = stabParent.getElementType(); childrenIndent = Indent.getNormalIndent( stabParentElementType == DO_BLOCK && codeStyleSettings(stabParent).ALIGN_UNMATCHED_CALL_DO_BLOCKS == childrenIndent = Indent.getNormalIndent(); } else {
blocks = buildArrowOperationChildren(parent, null); } else if (parentElementType == BIT_STRING) { blocks = buildBitStringChildren(parent, null, childrenWrap, Indent.getNormalIndent(), childrenAlignment); } else if (parentElementType == BLOCK_ITEM) { blocks = buildBlockItemChildren(parent, parentAlignment); blocks = buildLineChildren(parent); } else if (parentElementType == LIST) { blocks = buildListChildren(parent, null, childrenWrap, Indent.getNormalIndent(), childrenAlignment); } else if (MATCHED_CALL_TOKEN_SET.contains(parentElementType)) { blocks = buildMatchedCallChildren(parent, parentWrap, parentAlignment); blocks = buildTupleChildren(parent, null, childrenWrap, Indent.getNormalIndent(), childrenAlignment); } else if (WHEN_OPERATION_TOKEN_SET.contains(parentElementType)) { blocks = buildWhenOperationChildren(parent);
@NotNull @Override public ChildAttributes getChildAttributes(int newChildIndex) { return new ChildAttributes(Indent.getNormalIndent(false), null); }
@Nullable @Override public Indent getChildIndent(@NotNull PerlAstBlock block, int newChildIndex) { IElementType elementType = block.getElementType(); if (elementType == HTML_MASON_ARGS_BLOCK || elementType == HTML_MASON_ATTR_BLOCK) { return Indent.getNormalIndent(); } return super.getChildIndent(block, newChildIndex); } }