@Override public Indent getIndent() { return Indent.getNoneIndent(); }
@NotNull private List<com.intellij.formatting.Block> buildBlockListChildren(@NotNull ASTNode blockListNode, @Nullable Alignment parentAlignment) { return buildChildren( blockListNode, (child, childElementType, blockList) -> { blockList.add(buildChild(child, parentAlignment, Indent.getNoneIndent())); return blockList; } ); }
@NotNull private static Indent indentIfNotBrace(@NotNull ASTNode child) { return BRACES_TOKEN_SET.contains(child.getElementType()) ? Indent.getNoneIndent() : Indent.getNormalIndent(); }
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 @Override public FormattingModel createModel(@NotNull PsiElement element, @NotNull CodeStyleSettings settings) { Block block = new GoFormattingBlock(element.getNode(), null, Indent.getNoneIndent(), null, settings, createSpacingBuilder(settings)); return FormattingModelProvider.createFormattingModelForPsiFile(element.getContainingFile(), block, settings); }
@NotNull private List<com.intellij.formatting.Block> buildOperatorRuleChildren( @NotNull ASTNode operatorRule, @Nullable Wrap operatorWrap, @Nullable Alignment operatorAlignment, @Nullable Alignment rightCommentAlignment ) { final Alignment[] commentAlignment = {operatorAlignment}; Indent operatorIndent = Indent.getNoneIndent(); final Indent[] commentIndent = {operatorIndent}; return buildChildren( operatorRule, (child, childElementType, blockList) -> { if (OPERATOR_TOKEN_SET.contains(childElementType)) { blockList.add(buildChild(child, operatorWrap, operatorAlignment, operatorIndent)); commentAlignment[0] = rightCommentAlignment; commentIndent[0] = null; } else { blockList.add(buildChild(child, commentAlignment[0], commentIndent[0])); } return blockList; } ); }
@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(); }
@NotNull private List<com.intellij.formatting.Block> buildHeredocChildren(CompositeElement heredoc) { ASTNode heredocPrefix = heredoc.findChildByType(HEREDOC_PREFIX); int heredocPrefixLength = 0; if (heredocPrefix != null) { heredocPrefixLength = heredocPrefix.getTextLength(); } Indent indent = Indent.getNoneIndent(); int finalHeredocPrefixLength = heredocPrefixLength; return buildChildren( heredoc, (child, childElementType, blockList) -> { if (HEREDOC_LINE_TOKEN_SET.contains(childElementType)) { blockList.addAll(buildHeredocLineChildren(child, finalHeredocPrefixLength)); } else if (childElementType != HEREDOC_PREFIX) { /* The heredocPrefix while important for determining the significant white space in each heredoc line, is normal, insignificant whitespace when shifting the lines, so it has no block */ blockList.add(buildChild(child, indent)); } 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); }
blockList.add(buildChild(child, tailWrap, parentAlignment, Indent.getNoneIndent())); } else if (childElementType == COMMA) { blockList.add(buildChild(child));
@NotNull @Override public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) { if (!isGrammarViolated(element.getNode())) { BallerinaBlock rootBlock = new BallerinaBlock(element.getNode(), null, Indent.getNoneIndent(), null, settings, createSpaceBuilder(settings), new HashMap<>()); return FormattingModelProvider .createFormattingModelForPsiFile(element.getContainingFile(), rootBlock, settings); // If the plugin grammar tree is not generated correctly for the file, code reformat should not work. } else { AbstractBlock rootBlock = new AbstractBlock(element.getNode(), null, null) { @Nullable @Override public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) { return null; } @Override public boolean isLeaf() { return false; } @Override protected List<Block> buildChildren() { return new LinkedList<>(); } }; return FormattingModelProvider .createFormattingModelForPsiFile(element.getContainingFile(), rootBlock, settings); } }
blockList.addAll( buildEndOfExpressionChildren(child, finalChildrenAlignment, Indent.getNoneIndent()) ); } else if (childElementType == WHEN_INFIX_OPERATOR) {
return Indent.getNormalIndent(); return Indent.getNoneIndent();
(child, childElementType, blockList) -> { if (childElementType == closingElementType) { blockList.add(buildChild(child, tailWrap[0], closingAlignment, Indent.getNoneIndent())); } else if (childElementType == openingElementType) { blockList.add(buildChild(child, openingWrap));
@NotNull @Override public ChildAttributes getChildAttributes(int newChildIndex) { Indent childIndent = Indent.getNoneIndent(); if (myNode.getElementType() == BallerinaTypes.CALLABLE_UNIT_BODY) { childIndent = Indent.getNormalIndent();
@NotNull protected Indent getForeignIndent() { //noinspection ConstantConditions return getForeignIndent(Indent.getNoneIndent()); }
private ChildAttributes getAttributesByParent() { ASTNode astNode = myNode; final PsiElement psiParent = astNode.getPsi(); if (psiParent instanceof BashFile) { return new ChildAttributes(Indent.getNoneIndent(), null); } return new ChildAttributes(Indent.getNoneIndent(), null); }
@Nullable @Override public Indent getChildIndent(@NotNull PerlAstBlock block, int newChildIndex) { if (block.getElementType() == EmbeddedPerlParserDefinition.FILE) { return Indent.getNoneIndent(); } return super.getChildIndent(block, newChildIndex); } }
@NotNull @Override public ChildAttributes getChildAttributes(int newChildIndex) { if (isIncomplete()) { return new ChildAttributes(getIndent(), null); } return new ChildAttributes(Indent.getNoneIndent(), null); }
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(); } }