From ccb8c086848f35dc56884fac83b421cdbd537fa7 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Wed, 23 May 2012 18:43:47 +0400 Subject: [PATCH] Fix test and add special option for spacing around colon in type definitions --- .../jet/plugin/formatter/JetCodeStyleSettings.java | 3 +++ .../plugin/formatter/JetFormattingModelBuilder.java | 13 +++++++++---- .../JetLanguageCodeStyleSettingsProvider.java | 11 +++++++++++ .../functionWithTypeParameters.kt.after | 4 ++-- idea/testData/formatter/Parameters.kt | 5 ++++- idea/testData/formatter/Parameters_after.kt | 5 ++++- ...AroundTypeColon.kt => SpaceAroundExtendColon.kt} | 5 ++++- .../formatter/SpaceAroundExtendColon_after.kt | 12 ++++++++++++ .../formatter/SpaceAroundTypeColon_after.kt | 9 --------- .../jetbrains/jet/formatter/JetFormatterTest.java | 10 +++------- 10 files changed, 52 insertions(+), 25 deletions(-) rename idea/testData/formatter/{SpaceAroundTypeColon.kt => SpaceAroundExtendColon.kt} (71%) create mode 100644 idea/testData/formatter/SpaceAroundExtendColon_after.kt delete mode 100644 idea/testData/formatter/SpaceAroundTypeColon_after.kt diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetCodeStyleSettings.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetCodeStyleSettings.java index 60cc2c75c7d..1ce4399d9b9 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetCodeStyleSettings.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetCodeStyleSettings.java @@ -28,6 +28,9 @@ public class JetCodeStyleSettings extends CustomCodeStyleSettings { public boolean SPACE_BEFORE_TYPE_COLON = false; public boolean SPACE_AFTER_TYPE_COLON = true; + public boolean SPACE_BEFORE_EXTEND_COLON = false; + public boolean SPACE_AFTER_EXTEND_COLON = true; + public static JetCodeStyleSettings getInstance(Project project) { return CodeStyleSettingsManager.getSettings(project).getCustomSettings(JetCodeStyleSettings.class); } diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java index 375b08288cd..67d7d836f06 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java @@ -81,16 +81,21 @@ public class JetFormattingModelBuilder implements FormattingModelBuilder { .beforeInside(BLOCK, FUN).spaceIf(jetCommonSettings.SPACE_BEFORE_METHOD_LBRACE) // TODO: Ask for better API + // Type of the declaration colon .beforeInside(COLON, PROPERTY).spaceIf(jetSettings.SPACE_BEFORE_TYPE_COLON) .afterInside(COLON, PROPERTY).spaceIf(jetSettings.SPACE_AFTER_TYPE_COLON) - .beforeInside(COLON, CLASS).spaceIf(jetSettings.SPACE_BEFORE_TYPE_COLON) - .afterInside(COLON, CLASS).spaceIf(jetSettings.SPACE_AFTER_TYPE_COLON) .beforeInside(COLON, FUN).spaceIf(jetSettings.SPACE_BEFORE_TYPE_COLON) .afterInside(COLON, FUN).spaceIf(jetSettings.SPACE_AFTER_TYPE_COLON) - .beforeInside(COLON, TYPE_PARAMETER).spaceIf(jetSettings.SPACE_BEFORE_TYPE_COLON) - .afterInside(COLON, TYPE_PARAMETER).spaceIf(jetSettings.SPACE_AFTER_TYPE_COLON) .beforeInside(COLON, VALUE_PARAMETER).spaceIf(jetSettings.SPACE_BEFORE_TYPE_COLON) .afterInside(COLON, VALUE_PARAMETER).spaceIf(jetSettings.SPACE_AFTER_TYPE_COLON) + + // Extends or constraint colon + .beforeInside(COLON, TYPE_CONSTRAINT).spaceIf(jetSettings.SPACE_BEFORE_EXTEND_COLON) + .afterInside(COLON, TYPE_CONSTRAINT).spaceIf(jetSettings.SPACE_AFTER_EXTEND_COLON) + .beforeInside(COLON, CLASS).spaceIf(jetSettings.SPACE_BEFORE_EXTEND_COLON) + .afterInside(COLON, CLASS).spaceIf(jetSettings.SPACE_AFTER_EXTEND_COLON) + .beforeInside(COLON, TYPE_PARAMETER).spaceIf(jetSettings.SPACE_BEFORE_EXTEND_COLON) + .afterInside(COLON, TYPE_PARAMETER).spaceIf(jetSettings.SPACE_AFTER_EXTEND_COLON) ; } diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java index 2a27b24c311..13933b9f249 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java @@ -60,6 +60,9 @@ public class JetLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSetti " val test : Int = 12\n" + " return test\n" + " }\n" + + " private fun foo2():Int where T : List {\n" + + " return 0\n" + + " }\n" + "}"; } } @@ -93,6 +96,14 @@ public class JetLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSetti consumer.showCustomOption(JetCodeStyleSettings.class, "SPACE_BEFORE_TYPE_COLON", "Space before colon, after declarations' name", CodeStyleSettingsCustomizable.SPACES_OTHER); + + consumer.showCustomOption(JetCodeStyleSettings.class, "SPACE_AFTER_EXTEND_COLON", + "Space after colon in new type definition", + CodeStyleSettingsCustomizable.SPACES_OTHER); + + consumer.showCustomOption(JetCodeStyleSettings.class, "SPACE_BEFORE_EXTEND_COLON", + "Space before colon in new type definition", + CodeStyleSettingsCustomizable.SPACES_OTHER); break; case WRAPPING_AND_BRACES_SETTINGS: consumer.showStandardOptions( diff --git a/idea/testData/codeInsight/overrideImplement/functionWithTypeParameters.kt.after b/idea/testData/codeInsight/overrideImplement/functionWithTypeParameters.kt.after index eaf92a65bb1..b3056ffb517 100644 --- a/idea/testData/codeInsight/overrideImplement/functionWithTypeParameters.kt.after +++ b/idea/testData/codeInsight/overrideImplement/functionWithTypeParameters.kt.after @@ -6,8 +6,8 @@ trait Trait { class TraitImpl : Trait { - override fun > foo() - where B : Cloneable, B : Comparable { + override fun > foo() + where B: Cloneable, B: Comparable { throw UnsupportedOperationException() } } \ No newline at end of file diff --git a/idea/testData/formatter/Parameters.kt b/idea/testData/formatter/Parameters.kt index a9decafd29c..f754f326fa8 100644 --- a/idea/testData/formatter/Parameters.kt +++ b/idea/testData/formatter/Parameters.kt @@ -3,4 +3,7 @@ a: Int, b: String, c: Int, d: String, e: Int ) { -} \ No newline at end of file +} + +// SET_FALSE: SPACE_BEFORE_TYPE_COLON +// SET_TRUE: SPACE_AFTER_TYPE_COLON \ No newline at end of file diff --git a/idea/testData/formatter/Parameters_after.kt b/idea/testData/formatter/Parameters_after.kt index 81446e03a80..7d801a1931e 100644 --- a/idea/testData/formatter/Parameters_after.kt +++ b/idea/testData/formatter/Parameters_after.kt @@ -3,4 +3,7 @@ fun some( b: String, c: Int, d: String, e: Int ) { -} \ No newline at end of file +} + +// SET_FALSE: SPACE_BEFORE_TYPE_COLON +// SET_TRUE: SPACE_AFTER_TYPE_COLON \ No newline at end of file diff --git a/idea/testData/formatter/SpaceAroundTypeColon.kt b/idea/testData/formatter/SpaceAroundExtendColon.kt similarity index 71% rename from idea/testData/formatter/SpaceAroundTypeColon.kt rename to idea/testData/formatter/SpaceAroundExtendColon.kt index 0a6eca6c7fb..014d3e8e8a4 100644 --- a/idea/testData/formatter/SpaceAroundTypeColon.kt +++ b/idea/testData/formatter/SpaceAroundExtendColon.kt @@ -6,4 +6,7 @@ class Some :java.util.ArrayList() { val test:Int = 12 return test } -} \ No newline at end of file +} + +// SET_TRUE: SPACE_BEFORE_EXTEND_COLON +// SET_FALSE: SPACE_AFTER_EXTEND_COLON \ No newline at end of file diff --git a/idea/testData/formatter/SpaceAroundExtendColon_after.kt b/idea/testData/formatter/SpaceAroundExtendColon_after.kt new file mode 100644 index 00000000000..64eab3ec507 --- /dev/null +++ b/idea/testData/formatter/SpaceAroundExtendColon_after.kt @@ -0,0 +1,12 @@ +import java.util.ArrayList +import java.lang.Iterable + +class Some :java.util.ArrayList() { + fun some>(array: Array): Int { + val test: Int = 12 + return test + } +} + +// SET_TRUE: SPACE_BEFORE_EXTEND_COLON +// SET_FALSE: SPACE_AFTER_EXTEND_COLON \ No newline at end of file diff --git a/idea/testData/formatter/SpaceAroundTypeColon_after.kt b/idea/testData/formatter/SpaceAroundTypeColon_after.kt deleted file mode 100644 index 48961cdb78b..00000000000 --- a/idea/testData/formatter/SpaceAroundTypeColon_after.kt +++ /dev/null @@ -1,9 +0,0 @@ -import java.util.ArrayList -import java.lang.Iterable - -class Some :java.util.ArrayList() { - fun some>(array :Array) :Int { - val test :Int = 12 - return test - } -} \ 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 5a56dc6b949..d5712a31bd5 100644 --- a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java +++ b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java @@ -76,9 +76,7 @@ public class JetFormatterTest extends AbstractJetFormatterTest { } public void testParameters() throws Exception { - getJetSettings().SPACE_AFTER_TYPE_COLON = true; - getJetSettings().SPACE_BEFORE_TYPE_COLON = false; - doTest(); + doTestWithInvert(); } public void testRemoveSpacesAroundOperations() throws Exception { @@ -100,10 +98,8 @@ public class JetFormatterTest extends AbstractJetFormatterTest { doTestWithInvert(); } - public void testSpaceAroundTypeColon() throws Exception { - getJetSettings().SPACE_AFTER_TYPE_COLON = false; - getJetSettings().SPACE_BEFORE_TYPE_COLON = true; - doTest(); + public void testSpaceAroundExtendColon() throws Exception { + doTestWithInvert(); } public void testWhen() throws Exception {