From ae833306796d9484055d43a04332bb66b05930a3 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Mon, 20 Jun 2016 19:34:44 +0200 Subject: [PATCH] Format spaces inside curly braces in string template Fixes #KT-12791 --- .../jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt | 3 +++ .../formatter/CurlyBraceStringInterpolation.after.kt | 3 +++ idea/testData/formatter/CurlyBraceStringInterpolation.kt | 3 +++ .../jetbrains/kotlin/formatter/FormatterTestGenerated.java | 6 ++++++ 4 files changed, 15 insertions(+) create mode 100644 idea/testData/formatter/CurlyBraceStringInterpolation.after.kt create mode 100644 idea/testData/formatter/CurlyBraceStringInterpolation.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 4f605dfafc3..1f89181068a 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt @@ -214,6 +214,9 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing betweenInside(LPAR, DESTRUCTURING_DECLARATION, FOR).spaces(0) betweenInside(LOOP_RANGE, RPAR, FOR).spaces(0) + after(LONG_TEMPLATE_ENTRY_START).spaces(0) + before(LONG_TEMPLATE_ENTRY_END).spaces(0) + 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/CurlyBraceStringInterpolation.after.kt b/idea/testData/formatter/CurlyBraceStringInterpolation.after.kt new file mode 100644 index 00000000000..cb6376176c1 --- /dev/null +++ b/idea/testData/formatter/CurlyBraceStringInterpolation.after.kt @@ -0,0 +1,3 @@ +fun foo() { + "${1}" +} \ No newline at end of file diff --git a/idea/testData/formatter/CurlyBraceStringInterpolation.kt b/idea/testData/formatter/CurlyBraceStringInterpolation.kt new file mode 100644 index 00000000000..03487fdb6ad --- /dev/null +++ b/idea/testData/formatter/CurlyBraceStringInterpolation.kt @@ -0,0 +1,3 @@ +fun foo() { + "${ 1 }" +} \ 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 2683264cb24..ea745c1bbe0 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java @@ -151,6 +151,12 @@ public class FormatterTestGenerated extends AbstractFormatterTest { doTest(fileName); } + @TestMetadata("CurlyBraceStringInterpolation.after.kt") + public void testCurlyBraceStringInterpolation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/CurlyBraceStringInterpolation.after.kt"); + doTest(fileName); + } + @TestMetadata("DelegationList.after.kt") public void testDelegationList() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/DelegationList.after.kt");