From 45013ce8af38937cbdc34063cc01375e4ca2b5d3 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Sun, 20 Apr 2014 01:27:11 +0400 Subject: [PATCH] Fix formatting for multiline binary expressions #KT-4797 Fixed --- .../jet/plugin/formatter/JetBlock.java | 74 +++++++++++++++---- .../JetLanguageCodeStyleSettingsProvider.java | 1 + .../expressions/insideExpression1.kt | 4 +- .../expressions/insideExpression1.kt.after | 4 +- .../expressions/insideExpression2.kt.after | 4 +- .../expressions/insideExpression3.kt | 4 +- .../expressions/insideExpression3.kt.after | 4 +- .../expressions/insideExpression4.kt.after | 4 +- .../formatter/BinaryExpressions.after.inv.kt | 15 ++++ .../formatter/BinaryExpressions.after.kt | 15 ++++ idea/testData/formatter/BinaryExpressions.kt | 15 ++++ .../BinaryExpressionsBoolean.after.inv.kt | 32 ++++++++ .../BinaryExpressionsBoolean.after.kt | 32 ++++++++ .../formatter/BinaryExpressionsBoolean.kt | 32 ++++++++ .../InBinaryExpressionInMiddle.after.inv.kt | 6 ++ .../InBinaryExpressionInMiddle.after.kt | 6 ++ .../InBinaryExpressionInMiddle.kt | 5 ++ .../InBinaryExpressionUnfinished.after.inv.kt | 6 ++ .../InBinaryExpressionUnfinished.after.kt | 6 ++ .../InBinaryExpressionUnfinished.kt | 5 ++ ...essionsBeforeCloseParenthesis.after.inv.kt | 4 + ...ExpressionsBeforeCloseParenthesis.after.kt | 4 + ...BinaryExpressionsBeforeCloseParenthesis.kt | 3 + .../InExpressionsParentheses.after.inv.kt | 5 ++ .../InExpressionsParentheses.after.kt | 5 ++ .../InExpressionsParentheses.kt | 3 + ...sionsParenthesesBeforeOperand.after.inv.kt | 4 + ...pressionsParenthesesBeforeOperand.after.kt | 4 + .../InExpressionsParenthesesBeforeOperand.kt | 3 + .../formatter/JetFormatterTestGenerated.java | 24 +++++- ...JetTypingIndentationTestBaseGenerated.java | 50 +++++++++++++ 31 files changed, 354 insertions(+), 29 deletions(-) create mode 100644 idea/testData/formatter/BinaryExpressions.after.inv.kt create mode 100644 idea/testData/formatter/BinaryExpressions.after.kt create mode 100644 idea/testData/formatter/BinaryExpressions.kt create mode 100644 idea/testData/formatter/BinaryExpressionsBoolean.after.inv.kt create mode 100644 idea/testData/formatter/BinaryExpressionsBoolean.after.kt create mode 100644 idea/testData/formatter/BinaryExpressionsBoolean.kt create mode 100644 idea/testData/indentationOnNewline/InBinaryExpressionInMiddle.after.inv.kt create mode 100644 idea/testData/indentationOnNewline/InBinaryExpressionInMiddle.after.kt create mode 100644 idea/testData/indentationOnNewline/InBinaryExpressionInMiddle.kt create mode 100644 idea/testData/indentationOnNewline/InBinaryExpressionUnfinished.after.inv.kt create mode 100644 idea/testData/indentationOnNewline/InBinaryExpressionUnfinished.after.kt create mode 100644 idea/testData/indentationOnNewline/InBinaryExpressionUnfinished.kt create mode 100644 idea/testData/indentationOnNewline/InBinaryExpressionsBeforeCloseParenthesis.after.inv.kt create mode 100644 idea/testData/indentationOnNewline/InBinaryExpressionsBeforeCloseParenthesis.after.kt create mode 100644 idea/testData/indentationOnNewline/InBinaryExpressionsBeforeCloseParenthesis.kt create mode 100644 idea/testData/indentationOnNewline/InExpressionsParentheses.after.inv.kt create mode 100644 idea/testData/indentationOnNewline/InExpressionsParentheses.after.kt create mode 100644 idea/testData/indentationOnNewline/InExpressionsParentheses.kt create mode 100644 idea/testData/indentationOnNewline/InExpressionsParenthesesBeforeOperand.after.inv.kt create mode 100644 idea/testData/indentationOnNewline/InExpressionsParenthesesBeforeOperand.after.kt create mode 100644 idea/testData/indentationOnNewline/InExpressionsParenthesesBeforeOperand.kt diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java index cb29ea2cd94..de5bd23a4c9 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java @@ -22,7 +22,6 @@ import com.intellij.lang.ASTNode; import com.intellij.psi.TokenType; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CommonCodeStyleSettings; -import com.intellij.psi.formatter.FormatterUtil; import com.intellij.psi.formatter.common.AbstractBlock; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; @@ -111,19 +110,13 @@ public class JetBlock extends AbstractBlock { if (child.getElementType() == OPERATION_REFERENCE) { ASTNode operationNode = child.getFirstChildNode(); if (operationNode != null) { - return new JetBlock(operationNode, alignmentStrategy, Indent.getNoneIndent(), null, mySettings, mySpacingBuilder); + return new JetBlock(operationNode, alignmentStrategy, createChildIndent(child), null, mySettings, mySpacingBuilder); } } return new JetBlock(child, alignmentStrategy, createChildIndent(child), null, mySettings, mySpacingBuilder); } - private static Indent indentIfNotBrace(@NotNull ASTNode child) { - return child.getElementType() == RBRACE || child.getElementType() == LBRACE - ? Indent.getNoneIndent() - : Indent.getNormalIndent(); - } - private static ASTNode getPrevWithoutWhitespace(ASTNode node) { node = node.getTreePrev(); while (node != null && node.getElementType() == TokenType.WHITE_SPACE) { @@ -171,6 +164,10 @@ public class JetBlock extends AbstractBlock { return new ChildAttributes(Indent.getSpaceIndent(KDOC_COMMENT_INDENT), null); } + if (type == PARENTHESIZED) { + return super.getChildAttributes(newChildIndex); + } + if (isIncomplete()) { return super.getChildAttributes(newChildIndex); } @@ -184,28 +181,52 @@ public class JetBlock extends AbstractBlock { } private NodeAlignmentStrategy getChildrenAlignmentStrategy() { - CommonCodeStyleSettings jetCommonSettings = mySettings.getCommonSettings(JetLanguage.INSTANCE); + final CommonCodeStyleSettings jetCommonSettings = mySettings.getCommonSettings(JetLanguage.INSTANCE); JetCodeStyleSettings jetSettings = mySettings.getCustomSettings(JetCodeStyleSettings.class); - // Prepare default null strategy - NodeAlignmentStrategy strategy = myAlignmentStrategy; - // Redefine list of strategies for some special elements IElementType parentType = myNode.getElementType(); if (parentType == VALUE_PARAMETER_LIST) { - strategy = getAlignmentForChildInParenthesis( + return getAlignmentForChildInParenthesis( jetCommonSettings.ALIGN_MULTILINE_PARAMETERS, VALUE_PARAMETER, COMMA, jetCommonSettings.ALIGN_MULTILINE_METHOD_BRACKETS, LPAR, RPAR); } else if (parentType == VALUE_ARGUMENT_LIST) { - strategy = getAlignmentForChildInParenthesis( + return getAlignmentForChildInParenthesis( jetCommonSettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS, VALUE_ARGUMENT, COMMA, jetCommonSettings.ALIGN_MULTILINE_METHOD_BRACKETS, LPAR, RPAR); } else if (parentType == WHEN) { - strategy = getAlignmentForCaseBranch(jetSettings.ALIGN_IN_COLUMNS_CASE_BRANCH); + return getAlignmentForCaseBranch(jetSettings.ALIGN_IN_COLUMNS_CASE_BRANCH); } - return strategy; + else if (parentType == BINARY_EXPRESSION) { + return NodeAlignmentStrategy.fromTypes(AlignmentStrategy.wrap( + createAlignment(jetCommonSettings.ALIGN_MULTILINE_BINARY_OPERATION, getAlignment()))); + } + else if (parentType == PARENTHESIZED) { + return new NodeAlignmentStrategy() { + Alignment bracketsAlignment = jetCommonSettings.ALIGN_MULTILINE_BINARY_OPERATION ? Alignment.createAlignment() : null; + + @Nullable + @Override + public Alignment getAlignment(@NotNull ASTNode childNode) { + IElementType childNodeType = childNode.getElementType(); + ASTNode prev = getPrevWithoutWhitespace(childNode); + + if ((prev != null && prev.getElementType() == TokenType.ERROR_ELEMENT) || childNodeType == TokenType.ERROR_ELEMENT) { + return bracketsAlignment; + } + + if (childNodeType == LPAR || childNodeType == RPAR) { + return bracketsAlignment; + } + + return null; + } + }; + } + + return myAlignmentStrategy; } private static NodeAlignmentStrategy getAlignmentForChildInParenthesis( @@ -288,6 +309,14 @@ public class JetBlock extends AbstractBlock { .in(DOT_QUALIFIED_EXPRESSION, SAFE_ACCESS_EXPRESSION) .set(Indent.getContinuationWithoutFirstIndent(true)), + ASTIndentStrategy.forNode("Binary expressions") + .in(BINARY_EXPRESSION) + .set(Indent.getContinuationWithoutFirstIndent(false)), + + ASTIndentStrategy.forNode("Parenthesized expression") + .in(PARENTHESIZED) + .set(Indent.getContinuationWithoutFirstIndent(false)), + ASTIndentStrategy.forNode("KDoc comment indent") .in(DOC_COMMENT) .forType(KDocTokens.LEADING_ASTERISK, KDocTokens.END) @@ -338,4 +367,17 @@ public class JetBlock extends AbstractBlock { return Indent.getNoneIndent(); } + + @Nullable + private static Alignment createAlignment(boolean alignOption, @Nullable Alignment defaultAlignment) { + return alignOption ? createAlignmentOrDefault(null, defaultAlignment) : defaultAlignment; + } + + @Nullable + private static Alignment createAlignmentOrDefault(@Nullable Alignment base, @Nullable Alignment defaultAlignment) { + if (defaultAlignment == null) { + return base == null ? Alignment.createAlignment() : Alignment.createChildAlignment(base); + } + return defaultAlignment; + } } diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java index ed3823d2034..132d362d364 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java @@ -155,6 +155,7 @@ public class JetLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSetti "ALIGN_MULTILINE_PARAMETERS", "ALIGN_MULTILINE_PARAMETERS_IN_CALLS", "ALIGN_MULTILINE_METHOD_BRACKETS", + "ALIGN_MULTILINE_BINARY_OPERATION", "ELSE_ON_NEW_LINE", "WHILE_ON_NEW_LINE", "CATCH_ON_NEW_LINE", diff --git a/idea/testData/codeInsight/moveUpDown/expressions/insideExpression1.kt b/idea/testData/codeInsight/moveUpDown/expressions/insideExpression1.kt index 46f52c9bc6e..6c1b6a8e2bb 100644 --- a/idea/testData/codeInsight/moveUpDown/expressions/insideExpression1.kt +++ b/idea/testData/codeInsight/moveUpDown/expressions/insideExpression1.kt @@ -2,7 +2,7 @@ fun foo() { fun bar1() {} val x = 1 + - 2 + - 3 + 2 + + 3 fun bar2() {} } \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/insideExpression1.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/insideExpression1.kt.after index 779c2daf92a..55d052965e3 100644 --- a/idea/testData/codeInsight/moveUpDown/expressions/insideExpression1.kt.after +++ b/idea/testData/codeInsight/moveUpDown/expressions/insideExpression1.kt.after @@ -1,8 +1,8 @@ // MOVE: up fun foo() { val x = 1 + - 2 + - 3 + 2 + + 3 fun bar1() {} fun bar2() {} } \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/insideExpression2.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/insideExpression2.kt.after index 3fd9e8dc25d..4dd6797ec6c 100644 --- a/idea/testData/codeInsight/moveUpDown/expressions/insideExpression2.kt.after +++ b/idea/testData/codeInsight/moveUpDown/expressions/insideExpression2.kt.after @@ -3,6 +3,6 @@ fun foo() { fun bar1() {} fun bar2() {} val x = 1 + - 2 + - 3 + 2 + + 3 } \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/insideExpression3.kt b/idea/testData/codeInsight/moveUpDown/expressions/insideExpression3.kt index a9fb22d78c6..dbdc1419f8f 100644 --- a/idea/testData/codeInsight/moveUpDown/expressions/insideExpression3.kt +++ b/idea/testData/codeInsight/moveUpDown/expressions/insideExpression3.kt @@ -2,7 +2,7 @@ fun foo() { fun bar1() {} val x = 1 + - (2 + - 3) + (2 + + 3) fun bar2() {} } \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/insideExpression3.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/insideExpression3.kt.after index 43c1bc24136..6ddcd43094d 100644 --- a/idea/testData/codeInsight/moveUpDown/expressions/insideExpression3.kt.after +++ b/idea/testData/codeInsight/moveUpDown/expressions/insideExpression3.kt.after @@ -1,8 +1,8 @@ // MOVE: up fun foo() { val x = 1 + - (2 + - 3) + (2 + + 3) fun bar1() {} fun bar2() {} } \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/expressions/insideExpression4.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/insideExpression4.kt.after index 851f71d51d5..2bf179fe314 100644 --- a/idea/testData/codeInsight/moveUpDown/expressions/insideExpression4.kt.after +++ b/idea/testData/codeInsight/moveUpDown/expressions/insideExpression4.kt.after @@ -3,6 +3,6 @@ fun foo() { fun bar1() {} fun bar2() {} val x = 1 + - (2 + - 3) + (2 + + 3) } \ No newline at end of file diff --git a/idea/testData/formatter/BinaryExpressions.after.inv.kt b/idea/testData/formatter/BinaryExpressions.after.inv.kt new file mode 100644 index 00000000000..7373891e0e6 --- /dev/null +++ b/idea/testData/formatter/BinaryExpressions.after.inv.kt @@ -0,0 +1,15 @@ +fun test() { + val somelong = 1 + 2 + + 3 - 4 - + 5 * 6 * + 7 / 8 / + 9 % 10 % + 11 + + val withBrackets = 3 + + 4 - (5 + + 4 * 5) +} + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION +// Strage behaviour for disabled alignment is same to Java diff --git a/idea/testData/formatter/BinaryExpressions.after.kt b/idea/testData/formatter/BinaryExpressions.after.kt new file mode 100644 index 00000000000..9a85d7f163f --- /dev/null +++ b/idea/testData/formatter/BinaryExpressions.after.kt @@ -0,0 +1,15 @@ +fun test() { + val somelong = 1 + 2 + + 3 - 4 - + 5 * 6 * + 7 / 8 / + 9 % 10 % + 11 + + val withBrackets = 3 + + 4 - (5 + + 4 * 5) +} + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION +// Strage behaviour for disabled alignment is same to Java diff --git a/idea/testData/formatter/BinaryExpressions.kt b/idea/testData/formatter/BinaryExpressions.kt new file mode 100644 index 00000000000..d025533c751 --- /dev/null +++ b/idea/testData/formatter/BinaryExpressions.kt @@ -0,0 +1,15 @@ +fun test() { + val somelong = 1 + 2 + + 3 - 4 - + 5 * 6 * + 7 / 8 / + 9 % 10 % + 11 + + val withBrackets = 3 + + 4 - (5 + + 4 * 5) +} + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION +// Strage behaviour for disabled alignment is same to Java diff --git a/idea/testData/formatter/BinaryExpressionsBoolean.after.inv.kt b/idea/testData/formatter/BinaryExpressionsBoolean.after.inv.kt new file mode 100644 index 00000000000..6d6a9656c72 --- /dev/null +++ b/idea/testData/formatter/BinaryExpressionsBoolean.after.inv.kt @@ -0,0 +1,32 @@ +fun test() { + if (true + || false + || true) { + + } + + if (true || false + || true) { + + } + + if (true + || false + || true) { + + } + + if (true || + false || + true) { + + } + + true + || true + + false + && false +} + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION diff --git a/idea/testData/formatter/BinaryExpressionsBoolean.after.kt b/idea/testData/formatter/BinaryExpressionsBoolean.after.kt new file mode 100644 index 00000000000..dd5d40f56bc --- /dev/null +++ b/idea/testData/formatter/BinaryExpressionsBoolean.after.kt @@ -0,0 +1,32 @@ +fun test() { + if (true + || false + || true) { + + } + + if (true || false + || true) { + + } + + if (true + || false + || true) { + + } + + if (true || + false || + true) { + + } + + true + || true + + false + && false +} + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION diff --git a/idea/testData/formatter/BinaryExpressionsBoolean.kt b/idea/testData/formatter/BinaryExpressionsBoolean.kt new file mode 100644 index 00000000000..8cfedaf50e1 --- /dev/null +++ b/idea/testData/formatter/BinaryExpressionsBoolean.kt @@ -0,0 +1,32 @@ +fun test() { + if (true + || false + || true) { + + } + + if (true || false + || true) { + + } + + if (true + || false + || true) { + + } + + if (true || + false || + true) { + + } + + true + || true + + false + && false +} + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION diff --git a/idea/testData/indentationOnNewline/InBinaryExpressionInMiddle.after.inv.kt b/idea/testData/indentationOnNewline/InBinaryExpressionInMiddle.after.inv.kt new file mode 100644 index 00000000000..312ff0f41ca --- /dev/null +++ b/idea/testData/indentationOnNewline/InBinaryExpressionInMiddle.after.inv.kt @@ -0,0 +1,6 @@ +fun some() { + val test = 3 + + 4 +} + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InBinaryExpressionInMiddle.after.kt b/idea/testData/indentationOnNewline/InBinaryExpressionInMiddle.after.kt new file mode 100644 index 00000000000..075da5f2a33 --- /dev/null +++ b/idea/testData/indentationOnNewline/InBinaryExpressionInMiddle.after.kt @@ -0,0 +1,6 @@ +fun some() { + val test = 3 + + 4 +} + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InBinaryExpressionInMiddle.kt b/idea/testData/indentationOnNewline/InBinaryExpressionInMiddle.kt new file mode 100644 index 00000000000..b13efe4829f --- /dev/null +++ b/idea/testData/indentationOnNewline/InBinaryExpressionInMiddle.kt @@ -0,0 +1,5 @@ +fun some() { + val test = 3 + 4 +} + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InBinaryExpressionUnfinished.after.inv.kt b/idea/testData/indentationOnNewline/InBinaryExpressionUnfinished.after.inv.kt new file mode 100644 index 00000000000..b8295b6912c --- /dev/null +++ b/idea/testData/indentationOnNewline/InBinaryExpressionUnfinished.after.inv.kt @@ -0,0 +1,6 @@ +fun some() { + val test = 3 + + +} + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InBinaryExpressionUnfinished.after.kt b/idea/testData/indentationOnNewline/InBinaryExpressionUnfinished.after.kt new file mode 100644 index 00000000000..0553ece6bb5 --- /dev/null +++ b/idea/testData/indentationOnNewline/InBinaryExpressionUnfinished.after.kt @@ -0,0 +1,6 @@ +fun some() { + val test = 3 + + +} + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InBinaryExpressionUnfinished.kt b/idea/testData/indentationOnNewline/InBinaryExpressionUnfinished.kt new file mode 100644 index 00000000000..77e1e2b12d3 --- /dev/null +++ b/idea/testData/indentationOnNewline/InBinaryExpressionUnfinished.kt @@ -0,0 +1,5 @@ +fun some() { + val test = 3 + +} + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InBinaryExpressionsBeforeCloseParenthesis.after.inv.kt b/idea/testData/indentationOnNewline/InBinaryExpressionsBeforeCloseParenthesis.after.inv.kt new file mode 100644 index 00000000000..cfdfc44c85f --- /dev/null +++ b/idea/testData/indentationOnNewline/InBinaryExpressionsBeforeCloseParenthesis.after.inv.kt @@ -0,0 +1,4 @@ +val somelong = 3 + 4 - (3 + + ) + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InBinaryExpressionsBeforeCloseParenthesis.after.kt b/idea/testData/indentationOnNewline/InBinaryExpressionsBeforeCloseParenthesis.after.kt new file mode 100644 index 00000000000..7b2c9b4d286 --- /dev/null +++ b/idea/testData/indentationOnNewline/InBinaryExpressionsBeforeCloseParenthesis.after.kt @@ -0,0 +1,4 @@ +val somelong = 3 + 4 - (3 + + ) + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InBinaryExpressionsBeforeCloseParenthesis.kt b/idea/testData/indentationOnNewline/InBinaryExpressionsBeforeCloseParenthesis.kt new file mode 100644 index 00000000000..fdc43870763 --- /dev/null +++ b/idea/testData/indentationOnNewline/InBinaryExpressionsBeforeCloseParenthesis.kt @@ -0,0 +1,3 @@ +val somelong = 3 + 4 - (3 + ) + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InExpressionsParentheses.after.inv.kt b/idea/testData/indentationOnNewline/InExpressionsParentheses.after.inv.kt new file mode 100644 index 00000000000..0ea57e6e000 --- /dev/null +++ b/idea/testData/indentationOnNewline/InExpressionsParentheses.after.inv.kt @@ -0,0 +1,5 @@ +val somelong = 3 + 4 - ( + + ) + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InExpressionsParentheses.after.kt b/idea/testData/indentationOnNewline/InExpressionsParentheses.after.kt new file mode 100644 index 00000000000..9cd51d61a6f --- /dev/null +++ b/idea/testData/indentationOnNewline/InExpressionsParentheses.after.kt @@ -0,0 +1,5 @@ +val somelong = 3 + 4 - ( + + ) + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InExpressionsParentheses.kt b/idea/testData/indentationOnNewline/InExpressionsParentheses.kt new file mode 100644 index 00000000000..1d07622f010 --- /dev/null +++ b/idea/testData/indentationOnNewline/InExpressionsParentheses.kt @@ -0,0 +1,3 @@ +val somelong = 3 + 4 - () + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InExpressionsParenthesesBeforeOperand.after.inv.kt b/idea/testData/indentationOnNewline/InExpressionsParenthesesBeforeOperand.after.inv.kt new file mode 100644 index 00000000000..b4e0714eb63 --- /dev/null +++ b/idea/testData/indentationOnNewline/InExpressionsParenthesesBeforeOperand.after.inv.kt @@ -0,0 +1,4 @@ +val somelong = 3 + (3 * + 3) + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InExpressionsParenthesesBeforeOperand.after.kt b/idea/testData/indentationOnNewline/InExpressionsParenthesesBeforeOperand.after.kt new file mode 100644 index 00000000000..9bc20887717 --- /dev/null +++ b/idea/testData/indentationOnNewline/InExpressionsParenthesesBeforeOperand.after.kt @@ -0,0 +1,4 @@ +val somelong = 3 + (3 * + 3) + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InExpressionsParenthesesBeforeOperand.kt b/idea/testData/indentationOnNewline/InExpressionsParenthesesBeforeOperand.kt new file mode 100644 index 00000000000..ec7128bc809 --- /dev/null +++ b/idea/testData/indentationOnNewline/InExpressionsParenthesesBeforeOperand.kt @@ -0,0 +1,3 @@ +val somelong = 3 + (3 * 3) + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTestGenerated.java b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTestGenerated.java index 343a14b30ed..0b0fa227a3b 100644 --- a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTestGenerated.java @@ -36,7 +36,19 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest { @InnerTestClasses({Formatter.ModifierList.class}) public static class Formatter extends AbstractJetFormatterTest { public void testAllFilesPresentInFormatter() throws Exception { - JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/formatter"), Pattern.compile("^([^\\.]+)\\.after\\.kt.*$"), true); + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", + new File("idea/testData/formatter"), Pattern.compile("^([^\\.]+)\\.after\\.kt.*$"), + true); + } + + @TestMetadata("BinaryExpressions.after.kt") + public void testBinaryExpressions() throws Exception { + doTest("idea/testData/formatter/BinaryExpressions.after.kt"); + } + + @TestMetadata("BinaryExpressionsBoolean.after.kt") + public void testBinaryExpressionsBoolean() throws Exception { + doTest("idea/testData/formatter/BinaryExpressionsBoolean.after.kt"); } @TestMetadata("BlockFor.after.kt") @@ -407,6 +419,16 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/formatter"), Pattern.compile("^([^\\.]+)\\.after\\.inv\\.kt.*$"), true); } + @TestMetadata("BinaryExpressions.after.inv.kt") + public void testBinaryExpressions() throws Exception { + doTestInverted("idea/testData/formatter/BinaryExpressions.after.inv.kt"); + } + + @TestMetadata("BinaryExpressionsBoolean.after.inv.kt") + public void testBinaryExpressionsBoolean() throws Exception { + doTestInverted("idea/testData/formatter/BinaryExpressionsBoolean.after.inv.kt"); + } + @TestMetadata("CatchFinallyOnNewLine.after.inv.kt") public void testCatchFinallyOnNewLine() throws Exception { doTestInverted("idea/testData/formatter/CatchFinallyOnNewLine.after.inv.kt"); diff --git a/idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTestBaseGenerated.java b/idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTestBaseGenerated.java index 62d9f0293ac..409c72f79af 100644 --- a/idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTestBaseGenerated.java +++ b/idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTestBaseGenerated.java @@ -106,6 +106,31 @@ public class JetTypingIndentationTestBaseGenerated extends AbstractJetTypingInde doNewlineTest("idea/testData/indentationOnNewline/If.after.kt"); } + @TestMetadata("InBinaryExpressionInMiddle.after.kt") + public void testInBinaryExpressionInMiddle() throws Exception { + doNewlineTest("idea/testData/indentationOnNewline/InBinaryExpressionInMiddle.after.kt"); + } + + @TestMetadata("InBinaryExpressionUnfinished.after.kt") + public void testInBinaryExpressionUnfinished() throws Exception { + doNewlineTest("idea/testData/indentationOnNewline/InBinaryExpressionUnfinished.after.kt"); + } + + @TestMetadata("InBinaryExpressionsBeforeCloseParenthesis.after.kt") + public void testInBinaryExpressionsBeforeCloseParenthesis() throws Exception { + doNewlineTest("idea/testData/indentationOnNewline/InBinaryExpressionsBeforeCloseParenthesis.after.kt"); + } + + @TestMetadata("InExpressionsParentheses.after.kt") + public void testInExpressionsParentheses() throws Exception { + doNewlineTest("idea/testData/indentationOnNewline/InExpressionsParentheses.after.kt"); + } + + @TestMetadata("InExpressionsParenthesesBeforeOperand.after.kt") + public void testInExpressionsParenthesesBeforeOperand() throws Exception { + doNewlineTest("idea/testData/indentationOnNewline/InExpressionsParenthesesBeforeOperand.after.kt"); + } + @TestMetadata("NotFirstParameter.after.kt") public void testNotFirstParameter() throws Exception { doNewlineTest("idea/testData/indentationOnNewline/NotFirstParameter.after.kt"); @@ -171,6 +196,31 @@ public class JetTypingIndentationTestBaseGenerated extends AbstractJetTypingInde Pattern.compile("^([^\\.]+)\\.after\\.inv\\.kt.*$"), true); } + @TestMetadata("InBinaryExpressionInMiddle.after.inv.kt") + public void testInBinaryExpressionInMiddle() throws Exception { + doNewlineTestWithInvert("idea/testData/indentationOnNewline/InBinaryExpressionInMiddle.after.inv.kt"); + } + + @TestMetadata("InBinaryExpressionUnfinished.after.inv.kt") + public void testInBinaryExpressionUnfinished() throws Exception { + doNewlineTestWithInvert("idea/testData/indentationOnNewline/InBinaryExpressionUnfinished.after.inv.kt"); + } + + @TestMetadata("InBinaryExpressionsBeforeCloseParenthesis.after.inv.kt") + public void testInBinaryExpressionsBeforeCloseParenthesis() throws Exception { + doNewlineTestWithInvert("idea/testData/indentationOnNewline/InBinaryExpressionsBeforeCloseParenthesis.after.inv.kt"); + } + + @TestMetadata("InExpressionsParentheses.after.inv.kt") + public void testInExpressionsParentheses() throws Exception { + doNewlineTestWithInvert("idea/testData/indentationOnNewline/InExpressionsParentheses.after.inv.kt"); + } + + @TestMetadata("InExpressionsParenthesesBeforeOperand.after.inv.kt") + public void testInExpressionsParenthesesBeforeOperand() throws Exception { + doNewlineTestWithInvert("idea/testData/indentationOnNewline/InExpressionsParenthesesBeforeOperand.after.inv.kt"); + } + @TestMetadata("SettingAlignMultilineParametersInCalls.after.inv.kt") public void testSettingAlignMultilineParametersInCalls() throws Exception { doNewlineTestWithInvert("idea/testData/indentationOnNewline/SettingAlignMultilineParametersInCalls.after.inv.kt");