void (boolean keepInOneLine, TextRange textRange) { boolean lhsStatement = myChild1.getPsi() instanceof PsiStatement; boolean rhsStatement = myChild2.getPsi() instanceof PsiStatement; if (myParent instanceof JspCodeBlock) { myResult = Spacing.createSpacing(0, 0, 1, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); } else if (myRole1 == ChildRoleBase.NONE && !lhsStatement || myRole2 == ChildRoleBase.NONE && !rhsStatement) { IElementType firstElementType = myType1; if ( firstElementType == JavaTokenType.END_OF_LINE_COMMENT || firstElementType == JavaTokenType.C_STYLE_COMMENT) { myResult = Spacing.createDependentLFSpacing(0, 1, myParent.getTextRange(), mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); } else { myResult = null; } } else if (myRole1 == ChildRole.LBRACE) { int spacesAfterLBrace = mySettings.SPACE_WITHIN_BRACES ? 1 : 0; if (!keepInOneLine) { int blankLines = 1; if (myParent != null) { ASTNode parentNode = myParent.getNode(); if (parentNode != null) { ASTNode grandPa = parentNode.getTreeParent(); if (grandPa != null && grandPa.getElementType() == JavaElementType.METHOD) { blankLines += mySettings.BLANK_LINES_BEFORE_METHOD_BODY; } } } myResult = Spacing.createSpacing( spacesAfterLBrace, spacesAfterLBrace, blankLines, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); } else { myResult = Spacing.createDependentLFSpacing( spacesAfterLBrace, spacesAfterLBrace, textRange, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); } } else if (myRole2 == ChildRole.RBRACE) { int spacesBeforeRBrace = mySettings.SPACE_WITHIN_BRACES ? 1 : 0; if (!keepInOneLine) { myResult = Spacing.createSpacing( spacesBeforeRBrace, spacesBeforeRBrace, 1, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_BEFORE_RBRACE); } else { myResult = Spacing.createDependentLFSpacing( spacesBeforeRBrace, spacesBeforeRBrace, textRange, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_BEFORE_RBRACE); } } else if (myType1 == JavaElementType.SWITCH_LABEL_STATEMENT || myType2 == JavaElementType.SWITCH_LABEL_STATEMENT) { if (myType2 == JavaElementType.BLOCK_STATEMENT) { myResult = getSpaceBeforeLBrace(myChild2, mySettings.SPACE_BEFORE_SWITCH_LBRACE, null); } else { int lineFeeds = myType1 != JavaElementType.SWITCH_LABEL_STATEMENT || mySettings.CASE_STATEMENT_ON_NEW_LINE ? 1 : 0; myResult = Spacing.createSpacing(1, 1, lineFeeds, true, mySettings.KEEP_BLANK_LINES_IN_CODE); } } else if (lhsStatement && rhsStatement) { int minSpaces = 0; int minLineFeeds = 1; PsiElement psi = myChild1.getPsi(); // We want to avoid situations like below: // 1. Call 'introduce variable' refactoring for the code like 'System.out.println(1);'; // 2. When KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE is on, the output looks like 'int i = 1; System.out.println(i);'; // That's why we process the option only during the explicit reformat (directly invoked by an user). if ((mySettings.KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE && (FormatterUtil.isFormatterCalledExplicitly() || ApplicationManager.getApplication().isUnitTestMode())) || psi != null && PsiTreeUtil.hasErrorElements(psi)) { minSpaces = 1; minLineFeeds = 0; if (myChild1 != null) { ASTNode lastElement = myChild1; while (lastElement.getLastChildNode() != null) lastElement = lastElement.getLastChildNode(); //Not to place second statement on the same line with first one, if last ends with single line comment if (lastElement instanceof PsiComment && lastElement.getElementType() == JavaTokenType.END_OF_LINE_COMMENT) minLineFeeds = 1; } } myResult = Spacing.createSpacing(minSpaces, 0, minLineFeeds, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); } }