private static Spacing lineBreak(int lineBreaks, boolean keepLineBreaks) { return Spacing.createSpacing(0, 0, lineBreaks + 1, keepLineBreaks, keepLineBreaks ? 1 : 0); }
private Wrap createWrap(ASTNode child) { return Wrap.createWrap(WrapType.CHOP_DOWN_IF_LONG, false); }
@Override public Indent getIndent() { return Indent.getNoneIndent(); }
@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 @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; }
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); }
@Nullable @Override public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) { return mySpacingBuilder.getSpacing(this, child1, child2); }
@NotNull private List<com.intellij.formatting.Block> buildNoParenthesesKeywordPairChildren( @NotNull ASTNode noParenthesesKeywordPair ) { Wrap keywordKeyWrap = Wrap.createWrap(WrapType.CHOP_DOWN_IF_LONG, true); Indent keywordKeyIndent = Indent.getIndent(Indent.Type.NONE, true, false); Wrap keywordPairColonWrap = Wrap.createChildWrap(keywordKeyWrap, WrapType.NONE, true); Wrap keywordValueWrap = Wrap.createChildWrap(keywordKeyWrap, WrapType.NONE, true); return buildChildren( noParenthesesKeywordPair, (child, childElementType, blockList) -> { if (childElementType == ACCESS_EXPRESSION) { blockList.addAll(buildContainerValueAccessExpressionChildren(child, keywordValueWrap)); } else if (childElementType == KEYWORD_KEY) { blockList.add(buildChild(child, keywordKeyWrap, keywordKeyIndent)); } else if (childElementType == KEYWORD_PAIR_COLON) { blockList.add(buildChild(child, keywordPairColonWrap)); } else { blockList.add(buildChild(child, keywordValueWrap)); } return blockList; } ); }
@NotNull private Wrap mapContainerValueWrap(@Nullable Wrap parentWrap, @NotNull ASTNode mapOrStructOperation) { return Wrap.createChildWrap(parentWrap, mapContainerValueWrapType(mapOrStructOperation), true); }
@NotNull private static Indent indentIfNotBrace(@NotNull ASTNode child) { return BRACES_TOKEN_SET.contains(child.getElementType()) ? Indent.getNoneIndent() : Indent.getNormalIndent(); }
HeredocLineBlock(ASTNode heredocLine, int heredocPrefixLength, @NotNull SpacingBuilder spacingBuilder) { super(heredocLine, Wrap.createWrap(WrapType.NONE, false), null); this.heredocPrefixLength = heredocPrefixLength; this.spacingBuilder = spacingBuilder; }
/** * Returns a spacing object indicating what spaces and/or line breaks are added between two * specified children of this block. * * @param child1 the first child for which spacing is requested; * {@code null} if given {@code 'child2'} block is the first document block * @param child2 the second child for which spacing is requested. * @return the spacing instance, or null if no special spacing is required. If null is returned, * the formatter does not insert or delete spaces between the child blocks, but may insert * a line break if the line wraps at the position between the child blocks. * @see Spacing#createSpacing(int, int, int, boolean, int) * @see Spacing#getReadOnlySpacing() */ @Nullable @Override public Spacing getSpacing(@Nullable com.intellij.formatting.Block child1, @NotNull com.intellij.formatting.Block child2) { return spacingBuilder.getSpacing(this, child1, child2); }
private static Spacing none() { return Spacing.createSpacing(0, 0, 0, false, 0); }
@NotNull private List<com.intellij.formatting.Block> buildInterpolationChildren(@NotNull ASTNode interpolation) { return buildContainerChildren( interpolation, INTERPOLATION_START, Wrap.createWrap(WrapType.NONE, false), INTERPOLATION_END ); }
private static Spacing one() { return Spacing.createSpacing(1, 1, 0, false, 0); }
@NotNull private Wrap noParenthesesOneArgumentChildrenWrap(@NotNull ASTNode noParenthesesOneArgument) { return Wrap.createWrap( noParenthesesOneArgumentChildrenWrapType(noParenthesesOneArgument), // MUST NOT be `true` as wrapping the first argument disassociates the arguments with the call false ); }
@NotNull private Wrap listContainerValueWrap(@NotNull ASTNode list) { return Wrap.createWrap(listContainerValueWrapType(list), true); }
@NotNull private Wrap stabOperationWrap(@NotNull CompositeElement stab) { return Wrap.createWrap(stabOperationWrapType(stab), true); }
@NotNull private Wrap containerValueWrap(@NotNull ASTNode container) { return Wrap.createWrap(containerValueWrapType(container), true); }