@NotNull private WrapType mapContainerValueWrapType(ASTNode mapOrStructOperation) { ASTNode mapArguments = mapOrStructOperation.findChildByType(MAP_ARGUMENTS); WrapType wrapType = WrapType.CHOP_DOWN_IF_LONG; if (mapArguments != null) { ASTNode mapArgumentsChild = mapArguments.findChildByType(MAP_ARGUMENTS_CHILD_TOKEN_SET); if (mapArgumentsChild != null && mapArgumentsChild.findChildByType(MAP_TAIL_ARGUMENTS_TOKEN_SET) != null && !oneLinerUnmatchedCallBody(mapOrStructOperation)) { wrapType = WrapType.ALWAYS; } } return wrapType; }
@NotNull private WrapType containerValueWrapType(@NotNull ASTNode container) { WrapType wrapType; if (container.findChildByType(KEYWORDS) != null && !oneLinerUnmatchedCallBody(container)) { wrapType = WrapType.ALWAYS; } else { wrapType = WrapType.CHOP_DOWN_IF_LONG; } return wrapType; }
@NotNull private List<com.intellij.formatting.Block> buildSometimesBooleanOperationChildren( @NotNull ASTNode sometimesBooleanOperation ) { return buildAlignedOperandsOperationChildren( sometimesBooleanOperation, (codeStyleSettings) -> { ASTNode operatorRule = sometimesBooleanOperation.findChildByType( SOMETIMES_BOOLEAN_OPERATOR_RULE_TOKEN_SET ); boolean alignOperands = false; if (operatorRule != null) { ASTNode wordOperator = operatorRule.findChildByType(BOOLEAN_WORD_OPERATOR_TOKEN_SET); if (wordOperator != null && codeStyleSettings != null) { alignOperands = codeStyleSettings.ALIGN_BOOLEAN_OPERANDS; } } return alignOperands; }, SOMETIMES_BOOLEAN_OPERATOR_RULE_TOKEN_SET ); }
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(); }
@Override public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { assert startElement == endElement; com.intellij.lang.ASTNode parentNode = startElement.getNode(); com.intellij.lang.ASTNode whiteSpace = parentNode.findChildByType(TokenType.WHITE_SPACE); BlockSupport blockSupport = BlockSupport.getInstance(project); final int startOffset = whiteSpace.getStartOffset(); final int endOffset = startOffset + whiteSpace.getTextLength(); blockSupport.reparseRange(file, startOffset, endOffset, ""); } }
@NotNull private List<com.intellij.formatting.Block> buildBlockItemChildren(@NotNull ASTNode blockItem, @Nullable Alignment blockItemAlignment) { return buildChildren( blockItem, (child, childElementType, blockList) -> { if (childElementType == BLOCK_IDENTIFIER) { blockList.addAll(buildBlockIdentifierChildren(child, blockItemAlignment)); } else if (childElementType == END_OF_EXPRESSION) { blockList.addAll(buildEndOfExpressionChildren(child, null, null)); } else if (childElementType == STAB) { Wrap stabBodyChildrenWrap; if (child.findChildByType(STAB_BODY) != null) { stabBodyChildrenWrap = Wrap.createWrap(WrapType.ALWAYS, true); } else { stabBodyChildrenWrap = null; } blockList.addAll(buildStabChildren((CompositeElement) child, stabBodyChildrenWrap)); } else { blockList.add(buildChild(child)); } return blockList; } ); }
@NotNull private WrapType noParenthesesOneArgumentChildrenWrapType(@NotNull ASTNode noParenthesesOneArgument) { WrapType childrenWrapType; ASTNode noParenthesesKeywords = noParenthesesOneArgument.findChildByType(NO_PARENTHESES_KEYWORDS); if (noParenthesesKeywords != null) { ASTNode[] noParenthesesKeywordPairs = noParenthesesKeywords.getChildren(NO_PARENTHESES_KEYWORD_PAIR_TOKEN_SET); childrenWrapType = null; for (ASTNode noParenthesesKeywordPair : noParenthesesKeywordPairs) { if (oneLinerKeywordPair(noParenthesesKeywordPair)) { childrenWrapType = WrapType.CHOP_DOWN_IF_LONG; break; } } if (childrenWrapType == null) { childrenWrapType = noParenthesesOneArgumentWrapType(noParenthesesOneArgument); if (childrenWrapType == WrapType.ALWAYS && !noParenthesesKeywords.textContains('\n')) { childrenWrapType = WrapType.CHOP_DOWN_IF_LONG; } } } else { childrenWrapType = WrapType.CHOP_DOWN_IF_LONG; } return childrenWrapType; }
ASTNode openingElement = parent.findChildByType(openingElementType); ASTNode closingElement = parent.findChildByType(closingElementType);
@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; }
private boolean oneLinerKeywordPair(ASTNode keywordPair) { ASTNode keywordKey = keywordPair.findChildByType(KEYWORD_KEY); boolean oneLiner = false; if (keywordKey != null && keywordKey.getText().equals("do")) { ASTNode keywords = keywordPair.getTreeParent(); ASTNode keywordsParent = keywords.getTreeParent(); if (keywordsParent.getElementType() == NO_PARENTHESES_ONE_ARGUMENT) { ASTNode argumentsParent = keywordsParent.getTreeParent(); if (UNMATCHED_CALL_TOKEN_SET.contains(argumentsParent.getElementType())) { oneLiner = true; } } } return oneLiner; }
if (arrowOperation.findChildByType(ARROW_OPERATION_TOKEN_SET) == null) { operandAlignment[0] = nestedStartAlignment; } else {
Wrap stabBodyChildrenWrap; if (child.findChildByType(STAB_BODY) != null) { stabBodyChildrenWrap = Wrap.createWrap(WrapType.ALWAYS, true); } else {
if (o.getNode().findChildByType(GoTypes.COLON) != null) return referenceType; // means slice expression, todo: extract if needed GoType type = referenceType != null ? referenceType.getUnderlyingType() : null; if (type instanceof GoMapType) {
@Override public ASTNode getTagNode() { ASTNode node = getNode(); return node.findChildByType(R_TAG); }
@Nullable private ASTNode commandElementNode() { if (genericCommandElement == null) { //no other lock is used in the callees, it's safe to synchronize around the whole calculation synchronized (stateLock) { if (genericCommandElement == null) { genericCommandElement = getNode().findChildByType(BashElementTypes.GENERIC_COMMAND_ELEMENT); } } } return genericCommandElement; }
@Nullable @Override public PsiElement getNameIdentifier() { ASTNode node = getNode(); ASTNode modifierNode = node.findChildByType(MASON_METHOD_MODIFIER_NAME); if (modifierNode != null) { return modifierNode.getPsi(); } return null; } }
@Nullable public ASTNode getMethodNameNode() { ASTNode node = getNode(); return node.findChildByType(rule(RULE_rpcName)); }
@Nullable protected PsiElement getFormatterNameElement() { PsiElement formatterElement = getFormatterElement(); if (formatterElement != null) { ASTNode formatterNode = formatterElement.getNode(); ASTNode formatterNameNode = formatterNode.findChildByType(POD_FORMAT_NAME); return formatterNameNode == null ? null : formatterNameNode.getPsi(); } return null; }
@Override public PsiElement setName(@NonNls @NotNull String name) { ASTNode identifierNode = getNode().findChildByType(MathematicaElementTypes.IDENTIFIER); final PsiFileFactory fileFactory = PsiFileFactory.getInstance(getProject()); final MathematicaPsiFileImpl file = (MathematicaPsiFileImpl) fileFactory.createFileFromText("dummy.m", MathematicaFileType.INSTANCE, name); ASTNode newElm = file.getFirstChild().getNode().findChildByType(MathematicaElementTypes.IDENTIFIER); if (identifierNode != null && newElm != null) { getNode().replaceChild(identifierNode, newElm); } return this; }
@Override public PsiElement setName(@NonNls @NotNull String name) { ASTNode identifierNode = getNode().findChildByType(MathematicaElementTypes.IDENTIFIER); final PsiFileFactory fileFactory = PsiFileFactory.getInstance(getProject()); final MathematicaPsiFileImpl file = (MathematicaPsiFileImpl) fileFactory.createFileFromText("dummy.m", MathematicaFileType.INSTANCE, name); ASTNode newElm = file.getFirstChild().getNode().findChildByType(MathematicaElementTypes.IDENTIFIER); if (identifierNode != null && newElm != null) { getNode().replaceChild(identifierNode, newElm); } return this; }