From 4acb95acb5360fb56955adce021de7804aeef15c Mon Sep 17 00:00:00 2001 From: Andrius Semionovas Date: Wed, 31 May 2017 16:15:15 +0300 Subject: [PATCH] Fix KT-16725; Remove spaces between array indices --- .../jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt | 2 ++ idea/testData/formatter/ArrayAccess.after.kt | 4 ++-- idea/testData/formatter/SpaceBeforeIndices.after.kt | 2 ++ idea/testData/formatter/SpaceBeforeIndices.kt | 2 ++ .../poorlyFormattedExpression.kt.after | 2 +- .../jetbrains/kotlin/formatter/FormatterTestGenerated.java | 6 ++++++ 6 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 idea/testData/formatter/SpaceBeforeIndices.after.kt create mode 100644 idea/testData/formatter/SpaceBeforeIndices.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 55716ea2be6..628be78fe26 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt @@ -257,6 +257,8 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing around(BY_KEYWORD).spaces(1) betweenInside(IDENTIFIER, PROPERTY_DELEGATE, PROPERTY).spaces(1) + + before(INDICES).spaces(0) } custom { diff --git a/idea/testData/formatter/ArrayAccess.after.kt b/idea/testData/formatter/ArrayAccess.after.kt index a0bb195d191..84ee17c9fd7 100644 --- a/idea/testData/formatter/ArrayAccess.after.kt +++ b/idea/testData/formatter/ArrayAccess.after.kt @@ -8,13 +8,13 @@ fun test() { 1, 2 ] - a [ + a[ 1, 2 ] - a [ + a[ 1, 2 diff --git a/idea/testData/formatter/SpaceBeforeIndices.after.kt b/idea/testData/formatter/SpaceBeforeIndices.after.kt new file mode 100644 index 00000000000..884f8e254b1 --- /dev/null +++ b/idea/testData/formatter/SpaceBeforeIndices.after.kt @@ -0,0 +1,2 @@ +val array = emptyArray() +val foo = array[0] diff --git a/idea/testData/formatter/SpaceBeforeIndices.kt b/idea/testData/formatter/SpaceBeforeIndices.kt new file mode 100644 index 00000000000..e5852d86e43 --- /dev/null +++ b/idea/testData/formatter/SpaceBeforeIndices.kt @@ -0,0 +1,2 @@ +val array = emptyArray() +val foo = array [0] diff --git a/idea/testData/quickfix/addNewLineAfterAnnotations/poorlyFormattedExpression.kt.after b/idea/testData/quickfix/addNewLineAfterAnnotations/poorlyFormattedExpression.kt.after index 2b0cd2e5e6a..84d46eb12f0 100644 --- a/idea/testData/quickfix/addNewLineAfterAnnotations/poorlyFormattedExpression.kt.after +++ b/idea/testData/quickfix/addNewLineAfterAnnotations/poorlyFormattedExpression.kt.after @@ -6,5 +6,5 @@ annotation class Ann fun foo(y: IntArray) { // Currently it calls reformatting of base expression, but it seems to be a minor issue @Ann - y [0 + 9 * 4] = y[y [1]] + y[0 + 9 * 4] = y[y [1]] } diff --git a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java index 78671f447c1..548395871bc 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java @@ -596,6 +596,12 @@ public class FormatterTestGenerated extends AbstractFormatterTest { doTest(fileName); } + @TestMetadata("SpaceBeforeIndices.after.kt") + public void testSpaceBeforeIndices() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SpaceBeforeIndices.after.kt"); + doTest(fileName); + } + @TestMetadata("SpacedInsideParans.after.kt") public void testSpacedInsideParans() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SpacedInsideParans.after.kt");