@NotNull private List<com.intellij.formatting.Block> buildCapturedMultiplicationOperationChildren( ASTNode multiplicationOperation ) { List<com.intellij.formatting.Block> flattenedBlockList = buildOperationChildren(multiplicationOperation); List<com.intellij.formatting.Block> blockList = null; if (flattenedBlockList.size() == 3) { ASTBlock operatorBlock = (ASTBlock) flattenedBlockList.get(1); if (operatorBlock.getNode().getElementType() == DIVISION_OPERATOR) { ASTBlock rightOperandBlock = (ASTBlock) flattenedBlockList.get(2); // `/ARITY` confirmed if (rightOperandBlock.getNode().getElementType() == DECIMAL_WHOLE_NUMBER) { ASTBlock leftOperandBlock = (ASTBlock) flattenedBlockList.get(0); ASTNode leftOperand = leftOperandBlock.getNode(); IElementType leftOperandElementType = leftOperand.getElementType(); // `NAME/ARITY` confirmed if (NO_ARGUMENTS_CALL_TOKEN_SET.contains(leftOperandElementType) && leftOperand.findChildByType(DO_BLOCK) == null) { blockList = flattenedBlockList; } } } } if (blockList == null) { // don't flatten blockList = Collections.singletonList(buildChild(multiplicationOperation)); } return blockList; }
@NotNull @Override public ASTNode getNode() { return getRealBlock().getNode(); }
@Nullable @Override public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) { if (child1 == null) { return StatementBlock.NONE; } if (child2 instanceof ASTBlock) { ASTBlock block = (ASTBlock) child2; IElementType elementType = block.getNode().getElementType(); // Do not move trailing comments to new line. if (LINE_COMMENT.equals(elementType) || COMMENT.equals(elementType)) { return SPACE_OR_NEW_LINE; } } return StatementBlock.NEW_LINE; }
@Nullable @Override public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) { if (child2 instanceof ASTBlock) { ASTBlock block = (ASTBlock) child2; // Do not move semicolon after '}' to new line. IElementType elementType = block.getNode().getElementType(); if (SEMICOLON.equals(elementType)) { return NONE; } // Do not move trailing comments to new line. if (LINE_COMMENT.equals(elementType) || COMMENT.equals(elementType)) { return SPACE_OR_NEW_LINE; } } if (headerBlocks.contains(child1)) { return super.getSpacing(child1, child2); } return NEW_LINE; }
IElementType blockType = block instanceof ASTBlock ? PsiUtilCore.getElementType(((ASTBlock)block).getNode()) : null; if ((blockType == null || blockType == COMMA)) { blocksToGroup.add(block);
@Nullable public Alignment getChildAlignment(@NotNull PerlAstBlock block, int newChildIndex) { ASTNode node = block.getNode(); IElementType elementType = PsiUtilCore.getElementType(node); if (PerlFormattingContext.COMMA_LIKE_SEQUENCES.contains(elementType)) { return null; } // this is default algorythm from AbstractBlock#getFirstChildAlignment() List<Block> subBlocks = block.getSubBlocks(); for (final Block subBlock : subBlocks) { if (subBlock instanceof ASTBlock && PsiUtilCore.getElementType(((ASTBlock)subBlock).getNode()) == PerlElementTypes.COMMENT_LINE) { continue; } Alignment alignment = subBlock.getAlignment(); if (alignment != null) { return alignment; } } return null; }
ASTNode parentNode = parent.getNode(); IElementType parentNodeType = PsiUtilCore.getElementType(parentNode); ASTNode child1Node = ((ASTBlock)child1).getNode(); IElementType child1Type = child1Node.getElementType(); ASTNode child2Node = ((ASTBlock)child2).getNode(); IElementType child2Type = child2Node.getElementType();