From a520be55096fa74681fc8ed2ad3a41f08b5c7671 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Mon, 20 Jun 2016 19:48:29 +0200 Subject: [PATCH] Format spaces around semicolon Fixes #KT-12689 --- .../jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt | 3 +++ idea/testData/formatter/Semicolon.after.kt | 3 +++ idea/testData/formatter/Semicolon.kt | 3 +++ .../jetbrains/kotlin/formatter/FormatterTestGenerated.java | 6 ++++++ 4 files changed, 15 insertions(+) create mode 100644 idea/testData/formatter/Semicolon.after.kt create mode 100644 idea/testData/formatter/Semicolon.kt diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt index 8e80ac294d7..14441d6079a 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt @@ -219,6 +219,9 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing afterInside(ANNOTATION_ENTRY, ANNOTATED_EXPRESSION).spaces(1) + before(SEMICOLON).spaces(0) + after(SEMICOLON).spaces(1) + val TYPE_COLON_ELEMENTS = TokenSet.create(PROPERTY, FUN, VALUE_PARAMETER, DESTRUCTURING_DECLARATION_ENTRY, FUNCTION_LITERAL) beforeInside(COLON, TYPE_COLON_ELEMENTS) { spaceIf(kotlinSettings.SPACE_BEFORE_TYPE_COLON) } afterInside(COLON, TYPE_COLON_ELEMENTS) { spaceIf(kotlinSettings.SPACE_AFTER_TYPE_COLON) } diff --git a/idea/testData/formatter/Semicolon.after.kt b/idea/testData/formatter/Semicolon.after.kt new file mode 100644 index 00000000000..34f18f48f8c --- /dev/null +++ b/idea/testData/formatter/Semicolon.after.kt @@ -0,0 +1,3 @@ +fun foo() { + ""; "" +} \ No newline at end of file diff --git a/idea/testData/formatter/Semicolon.kt b/idea/testData/formatter/Semicolon.kt new file mode 100644 index 00000000000..a10d7b66b0f --- /dev/null +++ b/idea/testData/formatter/Semicolon.kt @@ -0,0 +1,3 @@ +fun foo() { + "" ; "" +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java index 981106d5189..8259ece326b 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java @@ -517,6 +517,12 @@ public class FormatterTestGenerated extends AbstractFormatterTest { doTest(fileName); } + @TestMetadata("Semicolon.after.kt") + public void testSemicolon() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/Semicolon.after.kt"); + doTest(fileName); + } + @TestMetadata("SingleLineFunctionLiteral.after.kt") public void testSingleLineFunctionLiteral() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SingleLineFunctionLiteral.after.kt");