private Indent calcCurrentIndent(final ASTNode child, final int state) { IElementType elementType = child.getElementType(); if (isRBrace(child) || elementType == JavaTokenType.AT) { return Indent.getNoneIndent(); } if (state == BEFORE_FIRST) return Indent.getNoneIndent(); if (elementType == JavaElementType.SWITCH_LABEL_STATEMENT) { return getCodeBlockInternalIndent(myChildrenIndent); } if (state == BEFORE_LBRACE) { if (isLBrace(child) || elementType == JavaTokenType.CLASS_KEYWORD || elementType == JavaTokenType.INTERFACE_KEYWORD || elementType == JavaTokenType.IDENTIFIER || elementType == JavaTokenType.ENUM_KEYWORD) { return Indent.getNoneIndent(); } else { return Indent.getContinuationIndent(myIndentSettings.USE_RELATIVE_INDENTS); } } else { if (isRBrace(child)) { return Indent.getNoneIndent(); } else { return getCodeBlockInternalIndent(myChildrenIndent); } } }
@Override @NotNull public ChildAttributes getChildAttributes(final int newChildIndex) { if (isAfter( newChildIndex, new IElementType[] {JavaDocElementType.DOC_COMMENT, JavaElementType.MODIFIER_LIST})) { return new ChildAttributes(Indent.getNoneIndent(), null); } else { if (getSubBlocks().size() == newChildIndex) { return new ChildAttributes(Indent.getNoneIndent(), null); } else { return new ChildAttributes(getCodeBlockInternalIndent(myChildrenIndent), null); } } }
@Override public Indent getIndent() { PsiElement element = myNode.getPsi(); if (isNode()) { return Indent.getIndent(Indent.Type.NORMAL, true, true); } return Indent.getNoneIndent(); }
private static Block generatePackageBlock(ASTNode node, CommonCodeStyleSettings settings) { return new GoPackageBlock( node, Alignment.createAlignment(), Indent.getNoneIndent(), Wrap.createWrap(WrapType.NONE, false), settings); }
private List<Block> buildSubBlocks() { final List<Block> blocks = new ArrayList<Block>(); Indent prevIndent = Indent.getNoneIndent(); // if (myNode.getElementType() == CoqTypes.PROOFPHRASE) return // Collections.unmodifiableList(blocks); for (ASTNode child = myNode.getFirstChildNode(); child != null; child = child.getTreeNext()) { if (!shouldCreateBlockFor(child)) continue; Block b = createChildBlock(child, Alignment.createAlignment(), prevIndent); prevIndent = b.getIndent(); blocks.add(b); } return Collections.unmodifiableList(blocks); }
@Nullable private ASTNode processCaseAndStatementAfter( final ArrayList<Block> result, ASTNode child, final Alignment childAlignment, final Wrap childWrap, final Indent indent) { final ArrayList<Block> localResult = new ArrayList<Block>(); processChild( localResult, child, AlignmentStrategy.getNullStrategy(), null, Indent.getNoneIndent()); child = child.getTreeNext(); Indent childIndent = Indent.getNormalIndent(); while (child != null) { if (child.getElementType() == JavaElementType.SWITCH_LABEL_STATEMENT || isRBrace(child)) { result.add(createCaseSectionBlock(localResult, childAlignment, indent, childWrap)); return child.getTreePrev(); } if (!FormatterUtil.containsWhiteSpacesOnly(child)) { if (child.getElementType() == JavaElementType.BLOCK_STATEMENT) { childIndent = Indent.getNoneIndent(); } boolean breakOrReturn = isBreakOrReturn(child); processChild(localResult, child, AlignmentStrategy.getNullStrategy(), null, childIndent); if (breakOrReturn) { result.add(createCaseSectionBlock(localResult, childAlignment, indent, childWrap)); return child; } } child = child.getTreeNext(); } result.add(createCaseSectionBlock(localResult, childAlignment, indent, childWrap)); return null; }
private RestBlock buildSubBlock(ASTNode child) { IElementType parentType = myNode.getElementType(); IElementType childType = child.getElementType(); IElementType grandparentType = myNode.getTreeParent() == null ? null : myNode.getTreeParent().getElementType(); Wrap wrap = null; Indent childIndent = Indent.getNoneIndent(); Alignment childAlignment = null; if (grandparentType == RestElementTypes.FIELD_LIST && parentType == RestElementTypes.LINE_TEXT && childType == RestTokenTypes.LINE) { childIndent = Indent.getNormalIndent(); } return new RestBlock(this, child, childAlignment, childIndent, wrap); }
@NotNull @Override public FormattingModel createModel( @NotNull PsiElement element, @NotNull CodeStyleSettings settings, @NotNull FormattingMode mode) { if (DUMP_FORMATTING_AST) { ASTNode fileNode = element.getContainingFile().getNode(); System.out.println("AST tree for " + element.getContainingFile().getName() + ":"); printAST(fileNode, 0); } final PyBlockContext context = new PyBlockContext(settings, createSpacingBuilder(settings), mode); final PyBlock block = new PyBlock(null, element.getNode(), null, Indent.getNoneIndent(), null, context); if (DUMP_FORMATTING_AST) { FormattingModelDumper.dumpFormattingModel(block, 2, System.out); } return FormattingModelProvider.createFormattingModelForPsiFile( element.getContainingFile(), block, settings); }
private CompositeBlockWrapper buildCompositeBlock( final Block rootBlock, @Nullable final CompositeBlockWrapper parent, final int index, @Nullable final WrapImpl currentWrapParent, boolean rootBlockIsRightBlock) { final CompositeBlockWrapper wrappedRootBlock = new CompositeBlockWrapper(rootBlock, myCurrentWhiteSpace, parent); if (index == 0) { wrappedRootBlock.arrangeParentTextRange(); } if (myRootBlockWrapper == null) { myRootBlockWrapper = wrappedRootBlock; myRootBlockWrapper.setIndent((IndentImpl) Indent.getNoneIndent()); } boolean blocksMayBeOfInterest = false; if (myPositionOfInterest != -1) { myResult.put(wrappedRootBlock, rootBlock); blocksMayBeOfInterest = true; } final boolean blocksAreReadOnly = rootBlock instanceof ReadOnlyBlockContainer || blocksMayBeOfInterest; State state = new State( rootBlock, wrappedRootBlock, currentWrapParent, blocksAreReadOnly, rootBlockIsRightBlock); myStates.push(state); return wrappedRootBlock; }
@NotNull @Override public ChildAttributes getChildAttributes(int newChildIndex) { return new ChildAttributes(Indent.getNoneIndent(), null); }
public static Block generateBlock( ASTNode node, Alignment alignment, CommonCodeStyleSettings settings) { return generateBlock(node, Indent.getNoneIndent(), alignment, settings); }
@NotNull public ChildAttributes getChildAttributes(int newChildIndex) { return new ChildAttributes(Indent.getNoneIndent(), Alignment.createAlignment()); // return ChildAttributes.DELEGATE_TO_NEXT_CHILD; }