ASTNode (@NotNull final List<Block> result, @NotNull ASTNode child, @NotNull AlignmentStrategy alignmentStrategy, final Wrap defaultWrap, Indent childIndent, int childOffset) { final IElementType childType = child.getElementType(); if (childType == JavaTokenType.CLASS_KEYWORD || childType == JavaTokenType.INTERFACE_KEYWORD) { myIsAfterClassKeyword = true; } if (childType == JavaElementType.METHOD_CALL_EXPRESSION) { Alignment alignment = shouldAlignChild(child) ? alignmentStrategy.getAlignment(childType) : null; result.add(createMethodCallExpressionBlock(child, arrangeChildWrap(child, defaultWrap), alignment, childIndent)); } else { IElementType nodeType = myNode.getElementType(); if (nodeType == JavaElementType.POLYADIC_EXPRESSION) nodeType = JavaElementType.BINARY_EXPRESSION; if (childType == JavaTokenType.LBRACE && nodeType == JavaElementType.ARRAY_INITIALIZER_EXPRESSION) { ArrayInitializerBlocksBuilder builder = new ArrayInitializerBlocksBuilder(myNode, myBlockFactory); List<Block> newlyCreated = builder.buildBlocks(); child = myNode.getLastChildNode(); result.addAll(newlyCreated); } else if (childType == JavaTokenType.LBRACE && nodeType == JavaElementType.ANNOTATION_ARRAY_INITIALIZER) { final Wrap wrap = Wrap.createWrap(getWrapType(mySettings.ARRAY_INITIALIZER_WRAP), false); child = processParenthesisBlock(JavaTokenType.LBRACE, JavaTokenType.RBRACE, result, child, WrappingStrategy.createDoNotWrapCommaStrategy(wrap), mySettings.ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION); } else if (childType == JavaTokenType.LPARENTH && nodeType == JavaElementType.EXPRESSION_LIST) { final Wrap wrap = Wrap.createWrap(getWrapType(mySettings.CALL_PARAMETERS_WRAP), false); if (mySettings.PREFER_PARAMETERS_WRAP && !isInsideMethodCall(myNode.getPsi())) { wrap.ignoreParentWraps(); } child = processParenthesisBlock(result, child, WrappingStrategy.createDoNotWrapCommaStrategy(wrap), mySettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS); } else if (childType == JavaTokenType.LPARENTH && nodeType == JavaElementType.PARAMETER_LIST) { ASTNode parent = myNode.getTreeParent(); boolean isLambdaParameterList = parent != null && parent.getElementType() == JavaElementType.LAMBDA_EXPRESSION; Wrap wrapToUse = isLambdaParameterList ? null : getMethodParametersWrap(); WrappingStrategy wrapStrategy = WrappingStrategy.createDoNotWrapCommaStrategy(wrapToUse); child = processParenthesisBlock(result, child, wrapStrategy, mySettings.ALIGN_MULTILINE_PARAMETERS); } else if (childType == JavaTokenType.LPARENTH && nodeType == JavaElementType.RECORD_HEADER) { Wrap wrap = Wrap.createWrap(getWrapType(myJavaSettings.RECORD_COMPONENTS_WRAP), false); WrappingStrategy wrapStrategy = WrappingStrategy.createDoNotWrapCommaStrategy(wrap); child = processParenthesisBlock(result, child, wrapStrategy, myJavaSettings.ALIGN_MULTILINE_RECORDS); } else if (childType == JavaTokenType.LPARENTH && nodeType == JavaElementType.DECONSTRUCTION_LIST) { Wrap wrap = Wrap.createWrap(getWrapType(myJavaSettings.DECONSTRUCTION_LIST_WRAP), false); WrappingStrategy wrapStrategy = WrappingStrategy.createDoNotWrapCommaStrategy(wrap); child = processParenthesisBlock(result, child, wrapStrategy, myJavaSettings.ALIGN_MULTILINE_DECONSTRUCTION_LIST_COMPONENTS); } else if (childType == JavaTokenType.LPARENTH && nodeType == JavaElementType.RESOURCE_LIST) { Wrap wrap = Wrap.createWrap(getWrapType(mySettings.RESOURCE_LIST_WRAP), false); child = processParenthesisBlock(result, child, WrappingStrategy.createDoNotWrapCommaStrategy(wrap), mySettings.ALIGN_MULTILINE_RESOURCES); } else if (childType == JavaTokenType.LPARENTH && nodeType == JavaElementType.ANNOTATION_PARAMETER_LIST) { AnnotationInitializerBlocksBuilder builder = new AnnotationInitializerBlocksBuilder(myNode, myBlockFactory); List<Block> newlyCreated = builder.buildBlocks(); child = myNode.getLastChildNode(); result.addAll(newlyCreated); } else if (childType == JavaTokenType.OR && nodeType == JavaElementType.TYPE) { // by default in "Foo | Bar | Baz" each child will have same (default) wrap, but we need to distinguish types and "|" Wrap wrap = Wrap.createWrap(WrapType.NONE, false); result.add(new SimpleJavaBlock(child, wrap, alignmentStrategy, childIndent, mySettings, myJavaSettings, myFormattingMode)); } else if (childType == JavaTokenType.LPARENTH && nodeType == JavaElementType.PARENTH_EXPRESSION) { child = processParenthesisBlock(result, child, WrappingStrategy.DO_NOT_WRAP, mySettings.ALIGN_MULTILINE_PARENTHESIZED_EXPRESSION); } else if (childType == JavaElementType.ENUM_CONSTANT && myNode instanceof ClassElement) { child = processEnumBlock(result, child, ((ClassElement)myNode).findEnumConstantListDelimiterPlace()); } else if (mySettings.TERNARY_OPERATION_SIGNS_ON_NEXT_LINE && isTernaryOperationSign(child)) { child = processTernaryOperationRange(result, child, defaultWrap, childIndent); } else if (childType == JavaElementType.FIELD) { child = processField(result, child, alignmentStrategy, defaultWrap, childIndent); } else if (childType == JavaElementType.LOCAL_VARIABLE || childType == JavaElementType.DECLARATION_STATEMENT && (nodeType == JavaElementType.METHOD || nodeType == JavaElementType.CODE_BLOCK) || mySettings.ALIGN_CONSECUTIVE_ASSIGNMENTS && childType == JavaElementType.EXPRESSION_STATEMENT) { result.add(new SimpleJavaBlock(child, defaultWrap, alignmentStrategy, childIndent, mySettings, myJavaSettings, myFormattingMode)); } else if (childType == JavaElementType.METHOD) { Wrap wrap = arrangeChildWrap(child, defaultWrap); Block block = createJavaBlock(child, mySettings, myJavaSettings, childIndent, wrap, alignmentStrategy, myFormattingMode); result.add(block); } else if (nodeType == JavaElementType.CASE_LABEL_ELEMENT_LIST) { Wrap wrap = Wrap.createWrap(getWrapType(mySettings.SWITCH_EXPRESSIONS_WRAP), false); WrappingStrategy wrapStrategy = WrappingStrategy.createDoNotWrapCommaStrategy(wrap); child = processSwitchExpression(result, child, wrapStrategy); } else { Alignment alignment = alignmentStrategy.getAlignment(childType); ChildAttributes delegateAttributes = getDelegateAttributes(result); if (delegateAttributes != null) { alignment = delegateAttributes.getAlignment(); if (delegateAttributes.getChildIndent() != null) { childIndent = delegateAttributes.getChildIndent(); } } AlignmentStrategy alignmentStrategyToUse = shouldAlignChild(child) ? AlignmentStrategy.wrap(alignment) : AlignmentStrategy.getNullStrategy(); if ((myAlignmentStrategy.getAlignment(nodeType, childType) != null && (nodeType == JavaElementType.IMPLEMENTS_LIST || nodeType == JavaElementType.CLASS)) // required to pass the same alignment strategy for consequent assignment expressions || (mySettings.ALIGN_CONSECUTIVE_ASSIGNMENTS && ((nodeType == JavaElementType.EXPRESSION_STATEMENT && childType == JavaElementType.ASSIGNMENT_EXPRESSION) || nodeType == JavaElementType.ASSIGNMENT_EXPRESSION))) { alignmentStrategyToUse = myAlignmentStrategy; } Wrap wrap = arrangeChildWrap(child, defaultWrap); Block block = createJavaBlock(child, mySettings, myJavaSettings, childIndent, wrap, alignmentStrategyToUse, childOffset, myFormattingMode); if (block instanceof AbstractJavaBlock javaBlock) { if (nodeType == JavaElementType.METHOD_CALL_EXPRESSION && childType == JavaElementType.REFERENCE_EXPRESSION) { javaBlock.setReservedWrap(getReservedWrap(nodeType), nodeType); javaBlock.setReservedWrap(getReservedWrap(childType), childType); } else if (nodeType == JavaElementType.BINARY_EXPRESSION) { javaBlock.setReservedWrap(defaultWrap, nodeType); } } result.add(block); } } return child; }