From b5d5e42e5bd98c26ab7f85cd2439026f589d8fe6 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Fri, 8 Jun 2012 21:58:43 +0400 Subject: [PATCH] KT-2217 Formatter fails to format unary minus #KT-2217 fixed --- .../formatter/JetFormattingModelBuilder.java | 2 +- ...perations.kt => SpacesAroundOperations.kt} | 18 ++++----- ...ter.kt => SpacesAroundOperations_after.kt} | 18 ++++----- ...kt => SpacesAroundOperations_after_inv.kt} | 18 ++++----- .../formatter/SpacesAroundUnaryOperations.kt | 20 ++++++++++ .../SpacesAroundUnaryOperations_after.kt | 20 ++++++++++ .../SpacesAroundUnaryOperations_after_inv.kt | 20 ++++++++++ .../jet/formatter/JetFormatterTest.java | 37 ++++--------------- 8 files changed, 96 insertions(+), 57 deletions(-) rename idea/testData/formatter/{AddSpacesAroundOperations.kt => SpacesAroundOperations.kt} (53%) rename idea/testData/formatter/{AddSpacesAroundOperations_after.kt => SpacesAroundOperations_after.kt} (56%) rename idea/testData/formatter/{RemoveSpacesAroundOperations_after.kt => SpacesAroundOperations_after_inv.kt} (53%) create mode 100644 idea/testData/formatter/SpacesAroundUnaryOperations.kt create mode 100644 idea/testData/formatter/SpacesAroundUnaryOperations_after.kt create mode 100644 idea/testData/formatter/SpacesAroundUnaryOperations_after_inv.kt diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java index 67d7d836f06..e27bfe94a29 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java @@ -73,7 +73,7 @@ public class JetFormattingModelBuilder implements FormattingModelBuilder { .around(TokenSet.create(ANDAND, OROR)).spaceIf(jetCommonSettings.SPACE_AROUND_LOGICAL_OPERATORS) .around(TokenSet.create(EQEQ, EXCLEQ, EQEQEQ, EXCLEQEQEQ)).spaceIf(jetCommonSettings.SPACE_AROUND_EQUALITY_OPERATORS) .aroundInside(TokenSet.create(LT, GT, LTEQ, GTEQ), BINARY_EXPRESSION).spaceIf(jetCommonSettings.SPACE_AROUND_RELATIONAL_OPERATORS) - .around(TokenSet.create(PLUS, MINUS)).spaceIf(jetCommonSettings.SPACE_AROUND_ADDITIVE_OPERATORS) + .aroundInside(TokenSet.create(PLUS, MINUS), BINARY_EXPRESSION).spaceIf(jetCommonSettings.SPACE_AROUND_ADDITIVE_OPERATORS) .aroundInside(TokenSet.create(MUL, DIV, PERC), BINARY_EXPRESSION).spaceIf(jetCommonSettings.SPACE_AROUND_MULTIPLICATIVE_OPERATORS) .around(TokenSet.create(PLUSPLUS, MINUSMINUS, EXCLEXCL, MINUS, PLUS, EXCL)).spaceIf(jetCommonSettings.SPACE_AROUND_UNARY_OPERATOR) .around(RANGE).spaceIf(jetSettings.SPACE_AROUND_RANGE) diff --git a/idea/testData/formatter/AddSpacesAroundOperations.kt b/idea/testData/formatter/SpacesAroundOperations.kt similarity index 53% rename from idea/testData/formatter/AddSpacesAroundOperations.kt rename to idea/testData/formatter/SpacesAroundOperations.kt index df1e093c0fc..4a2f66d9f1b 100644 --- a/idea/testData/formatter/AddSpacesAroundOperations.kt +++ b/idea/testData/formatter/SpacesAroundOperations.kt @@ -26,14 +26,14 @@ class Some { 12%3*12/3 - !true - int++ - ++int - int-- - --int - +12 - -12 - 1..2 } -} \ No newline at end of file +} + +// SET_TRUE: SPACE_AROUND_ASSIGNMENT_OPERATORS +// SET_TRUE: SPACE_AROUND_LOGICAL_OPERATORS +// SET_TRUE: SPACE_AROUND_EQUALITY_OPERATORS +// SET_TRUE: SPACE_AROUND_RELATIONAL_OPERATORS +// SET_TRUE: SPACE_AROUND_ADDITIVE_OPERATORS +// SET_TRUE: SPACE_AROUND_MULTIPLICATIVE_OPERATORS +// SET_TRUE: SPACE_AROUND_RANGE \ No newline at end of file diff --git a/idea/testData/formatter/AddSpacesAroundOperations_after.kt b/idea/testData/formatter/SpacesAroundOperations_after.kt similarity index 56% rename from idea/testData/formatter/AddSpacesAroundOperations_after.kt rename to idea/testData/formatter/SpacesAroundOperations_after.kt index 44663a42413..ad75a93c7a8 100644 --- a/idea/testData/formatter/AddSpacesAroundOperations_after.kt +++ b/idea/testData/formatter/SpacesAroundOperations_after.kt @@ -26,14 +26,14 @@ class Some { 12 % 3 * 12 / 3 - ! true - int ++ - ++ int - int -- - -- int - + 12 - - 12 - 1 .. 2 } -} \ No newline at end of file +} + +// SET_TRUE: SPACE_AROUND_ASSIGNMENT_OPERATORS +// SET_TRUE: SPACE_AROUND_LOGICAL_OPERATORS +// SET_TRUE: SPACE_AROUND_EQUALITY_OPERATORS +// SET_TRUE: SPACE_AROUND_RELATIONAL_OPERATORS +// SET_TRUE: SPACE_AROUND_ADDITIVE_OPERATORS +// SET_TRUE: SPACE_AROUND_MULTIPLICATIVE_OPERATORS +// SET_TRUE: SPACE_AROUND_RANGE \ No newline at end of file diff --git a/idea/testData/formatter/RemoveSpacesAroundOperations_after.kt b/idea/testData/formatter/SpacesAroundOperations_after_inv.kt similarity index 53% rename from idea/testData/formatter/RemoveSpacesAroundOperations_after.kt rename to idea/testData/formatter/SpacesAroundOperations_after_inv.kt index 10c5e9843d3..57936cd357f 100644 --- a/idea/testData/formatter/RemoveSpacesAroundOperations_after.kt +++ b/idea/testData/formatter/SpacesAroundOperations_after_inv.kt @@ -26,14 +26,14 @@ class Some { 12%3*12/3 - !true - int++ - ++int - int-- - --int - +12 - -12 - 1..2 } -} \ No newline at end of file +} + +// SET_TRUE: SPACE_AROUND_ASSIGNMENT_OPERATORS +// SET_TRUE: SPACE_AROUND_LOGICAL_OPERATORS +// SET_TRUE: SPACE_AROUND_EQUALITY_OPERATORS +// SET_TRUE: SPACE_AROUND_RELATIONAL_OPERATORS +// SET_TRUE: SPACE_AROUND_ADDITIVE_OPERATORS +// SET_TRUE: SPACE_AROUND_MULTIPLICATIVE_OPERATORS +// SET_TRUE: SPACE_AROUND_RANGE \ No newline at end of file diff --git a/idea/testData/formatter/SpacesAroundUnaryOperations.kt b/idea/testData/formatter/SpacesAroundUnaryOperations.kt new file mode 100644 index 00000000000..6b37c0db480 --- /dev/null +++ b/idea/testData/formatter/SpacesAroundUnaryOperations.kt @@ -0,0 +1,20 @@ +fun test() { + ! true + !true + int ++ + int++ + ++ int + ++int + int -- + int-- + -- int + --int + + 12 + +12 + - 12 + -12 + test!! + test !! +} + +// SET_TRUE: SPACE_AROUND_UNARY_OPERATOR \ No newline at end of file diff --git a/idea/testData/formatter/SpacesAroundUnaryOperations_after.kt b/idea/testData/formatter/SpacesAroundUnaryOperations_after.kt new file mode 100644 index 00000000000..3f2ff86e787 --- /dev/null +++ b/idea/testData/formatter/SpacesAroundUnaryOperations_after.kt @@ -0,0 +1,20 @@ +fun test() { + ! true + ! true + int ++ + int ++ + ++ int + ++ int + int -- + int -- + -- int + -- int + + 12 + + 12 + - 12 + - 12 + test !! + test !! +} + +// SET_TRUE: SPACE_AROUND_UNARY_OPERATOR \ No newline at end of file diff --git a/idea/testData/formatter/SpacesAroundUnaryOperations_after_inv.kt b/idea/testData/formatter/SpacesAroundUnaryOperations_after_inv.kt new file mode 100644 index 00000000000..2888c58311a --- /dev/null +++ b/idea/testData/formatter/SpacesAroundUnaryOperations_after_inv.kt @@ -0,0 +1,20 @@ +fun test() { + !true + !true + int++ + int++ + ++int + ++int + int-- + int-- + --int + --int + +12 + +12 + -12 + -12 + test!! + test!! +} + +// SET_TRUE: SPACE_AROUND_UNARY_OPERATOR \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java index d5712a31bd5..5674b8d1337 100644 --- a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java +++ b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java @@ -24,20 +24,6 @@ import org.jetbrains.jet.plugin.formatter.JetCodeStyleSettings; * Based on com.intellij.psi.formatter.java.JavaFormatterTest */ public class JetFormatterTest extends AbstractJetFormatterTest { - public void testAddSpacesAroundOperations() throws Exception { - getSettings().SPACE_AROUND_ASSIGNMENT_OPERATORS = true; - getSettings().SPACE_AROUND_LOGICAL_OPERATORS = true; - getSettings().SPACE_AROUND_EQUALITY_OPERATORS = true; - getSettings().SPACE_AROUND_RELATIONAL_OPERATORS = true; - getSettings().SPACE_AROUND_ADDITIVE_OPERATORS = true; - getSettings().SPACE_AROUND_MULTIPLICATIVE_OPERATORS = true; - getSettings().SPACE_AROUND_UNARY_OPERATOR = true; - getJetSettings().SPACE_AROUND_RANGE = true; - - doTest(); - - getSettings().clearCodeStyleSettings(); - } public void testBlockFor() throws Exception { doTest(); @@ -79,21 +65,6 @@ public class JetFormatterTest extends AbstractJetFormatterTest { doTestWithInvert(); } - public void testRemoveSpacesAroundOperations() throws Exception { - getSettings().SPACE_AROUND_ASSIGNMENT_OPERATORS = false; - getSettings().SPACE_AROUND_LOGICAL_OPERATORS = false; - getSettings().SPACE_AROUND_EQUALITY_OPERATORS = false; - getSettings().SPACE_AROUND_RELATIONAL_OPERATORS = false; - getSettings().SPACE_AROUND_ADDITIVE_OPERATORS = false; - getSettings().SPACE_AROUND_MULTIPLICATIVE_OPERATORS = false; - getSettings().SPACE_AROUND_UNARY_OPERATOR = false; - getJetSettings().SPACE_AROUND_RANGE = false; - - doTest(); - - getSettings().clearCodeStyleSettings(); - } - public void testRightBracketOnNewLine() throws Exception { doTestWithInvert(); } @@ -102,6 +73,14 @@ public class JetFormatterTest extends AbstractJetFormatterTest { doTestWithInvert(); } + public void testSpacesAroundOperations() throws Exception { + doTestWithInvert(); + } + + public void testSpacesAroundUnaryOperations() throws Exception { + doTestWithInvert(); + } + public void testWhen() throws Exception { doTest(); }