From 5652fa762f1e06bcb75256d36a0063b28266e35f Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 20 Dec 2017 16:34:59 +0100 Subject: [PATCH] Force no line break after dot in chained calls #KT-20362 Fixed --- .../kotlin/idea/formatter/kotlinSpacingRules.kt | 6 ++++-- idea/testData/formatter/KT20362.after.kt | 6 ++++++ idea/testData/formatter/KT20362.kt | 8 ++++++++ .../SpacesInQualifiedExpressions.after.kt | 16 ++++------------ .../kotlin/formatter/FormatterTestGenerated.java | 12 ++++++++++++ .../issues/unfinishedReferenceExpression.kt | 3 +-- 6 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 idea/testData/formatter/KT20362.after.kt create mode 100644 idea/testData/formatter/KT20362.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 81f4d7f006c..8d7fd73a19d 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt @@ -291,8 +291,10 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing afterInside(CONSTRUCTOR_KEYWORD, PRIMARY_CONSTRUCTOR).spaces(0) betweenInside(IDENTIFIER, TYPE_PARAMETER_LIST, CLASS).spaces(0) - aroundInside(DOT, DOT_QUALIFIED_EXPRESSION).spaces(0) - aroundInside(SAFE_ACCESS, SAFE_ACCESS_EXPRESSION).spaces(0) + beforeInside(DOT, DOT_QUALIFIED_EXPRESSION).spaces(0) + afterInside(DOT, DOT_QUALIFIED_EXPRESSION).spacesNoLineBreak(0) + beforeInside(SAFE_ACCESS, SAFE_ACCESS_EXPRESSION).spaces(0) + afterInside(SAFE_ACCESS, SAFE_ACCESS_EXPRESSION).spacesNoLineBreak(0) between(MODIFIERS_LIST_ENTRIES, MODIFIERS_LIST_ENTRIES).spaces(1) diff --git a/idea/testData/formatter/KT20362.after.kt b/idea/testData/formatter/KT20362.after.kt new file mode 100644 index 00000000000..580e03550b9 --- /dev/null +++ b/idea/testData/formatter/KT20362.after.kt @@ -0,0 +1,6 @@ +val ret = (DB.Article innerJoin DB.Project).slice(DB.Article.project, DB.Article.project.count()).select { + filterBlogs(params) + }.groupBy(DB.Article.project).map { + val count = it[DB.Article.project.count()] + val project = it[DB.Article.team.count()] + } \ No newline at end of file diff --git a/idea/testData/formatter/KT20362.kt b/idea/testData/formatter/KT20362.kt new file mode 100644 index 00000000000..bf7fc7dc198 --- /dev/null +++ b/idea/testData/formatter/KT20362.kt @@ -0,0 +1,8 @@ +val ret = (DB.Article innerJoin DB.Project). + slice(DB.Article.project, DB.Article.project.count()). + select { + filterBlogs(params) + }.groupBy(DB.Article.project).map { + val count = it[DB.Article.project.count()] + val project = it[DB.Article.team.count()] +} \ No newline at end of file diff --git a/idea/testData/formatter/SpacesInQualifiedExpressions.after.kt b/idea/testData/formatter/SpacesInQualifiedExpressions.after.kt index 3363a87a71d..7a3c5280c58 100644 --- a/idea/testData/formatter/SpacesInQualifiedExpressions.after.kt +++ b/idea/testData/formatter/SpacesInQualifiedExpressions.after.kt @@ -5,13 +5,9 @@ interface Test { fun test(t: Test) { t.foo() - t. - foo() + t.foo() - t. - - - foo() + t.foo() t @@ -24,13 +20,9 @@ fun test(t: Test) { t?.foo() - t?. - foo() + t?.foo() - t?. - - - foo() + t?.foo() t diff --git a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java index e5bd0a3e77c..dfed15559e1 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java @@ -524,6 +524,18 @@ public class FormatterTestGenerated extends AbstractFormatterTest { doTest(fileName); } + @TestMetadata("KT15099.after.kt") + public void testKT15099() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/KT15099.after.kt"); + doTest(fileName); + } + + @TestMetadata("KT20362.after.kt") + public void testKT20362() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/KT20362.after.kt"); + doTest(fileName); + } + @TestMetadata("KeepLineBreak.after.kt") public void testKeepLineBreak() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/KeepLineBreak.after.kt"); diff --git a/j2k/testData/fileOrElement/issues/unfinishedReferenceExpression.kt b/j2k/testData/fileOrElement/issues/unfinishedReferenceExpression.kt index 64a6c19e416..2a893313381 100644 --- a/j2k/testData/fileOrElement/issues/unfinishedReferenceExpression.kt +++ b/j2k/testData/fileOrElement/issues/unfinishedReferenceExpression.kt @@ -2,7 +2,6 @@ class JavaClass { var v = "" fun m(s: String) { - s. - this.v. + s.this.v. } } \ No newline at end of file