From e7ff0315d47515a91e2c2d517aac41cf196cd692 Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Tue, 10 Dec 2019 16:43:40 +0700 Subject: [PATCH] Formatter: fix line break before value parameter with annotation #KT-23811 Fixed --- .../idea/formatter/KotlinCommonBlock.kt | 9 +--- .../ParameterListWrapAlways.after.kt | 41 +++++++++++++++++++ .../parameterList/ParameterListWrapAlways.kt | 9 ++++ 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt index d5da6fc3654..ec9a85a3f54 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt @@ -594,12 +594,7 @@ abstract class KotlinCommonBlock( parentElementType === SECONDARY_CONSTRUCTOR ) { val wrap = Wrap.createWrap(commonSettings.METHOD_PARAMETERS_WRAP, false) - return { childElement -> - if (childElement.elementType === VALUE_PARAMETER && !childElement.startsWithAnnotation()) - wrap - else - null - } + return { childElement -> wrap.takeIf { childElement.elementType === VALUE_PARAMETER } } } } @@ -701,8 +696,6 @@ abstract class KotlinCommonBlock( } } -private fun ASTNode.startsWithAnnotation() = firstChildNode?.firstChildNode?.elementType == ANNOTATION_ENTRY - private fun ASTNode.isFirstParameter(): Boolean = treePrev?.elementType == LPAR private fun wrapAfterAnnotation(wrapType: Int): WrappingStrategy { diff --git a/idea/testData/formatter/parameterList/ParameterListWrapAlways.after.kt b/idea/testData/formatter/parameterList/ParameterListWrapAlways.after.kt index 6aba36ed055..270799b10df 100644 --- a/idea/testData/formatter/parameterList/ParameterListWrapAlways.after.kt +++ b/idea/testData/formatter/parameterList/ParameterListWrapAlways.after.kt @@ -18,6 +18,16 @@ fun testtesttesttest(foofoo: Int, foobar: Int, barfoo: Int) +fun testtesttesttest(foofoo: Int, + @Some barbar: Int, + foobar: Int, + barfoo: Int) + +fun testtesttesttest(@Some foofoo: Int, + @Some barbar: Int, + @Some foobar: Int, + barfoo: Int) + fun test() { for (foo: Int in bar) { @@ -130,3 +140,34 @@ class H(sn1: SN, constructor(sn1: SN) { } } + +class I(sn1: SN, + @field:Some val sn2: SN, + sn3: SN, + sn4: SN, + sn5: SN, + sn6: SN, + sn6: SN, + sn8: SN, + sn9: SN, + sn10: SN, + sn11: SN, + sn12: SN, + sn13: SN, + sn14: SN) { + constructor(sn1: SN, + sn2: SN, + sn3: SN, + @Some sn4: SN, + sn5: SN, + sn6: SN, + sn6: SN, + sn8: SN, + sn9: SN, + sn10: SN, + sn11: SN, + sn12: SN, + sn13: SN, + sn14: SN) { + } +} diff --git a/idea/testData/formatter/parameterList/ParameterListWrapAlways.kt b/idea/testData/formatter/parameterList/ParameterListWrapAlways.kt index 7b6899c72ab..9be8076fce0 100644 --- a/idea/testData/formatter/parameterList/ParameterListWrapAlways.kt +++ b/idea/testData/formatter/parameterList/ParameterListWrapAlways.kt @@ -14,6 +14,10 @@ fun test(foo: Int, bar: Int) fun testtesttesttest(foofoo: Int, barbar: Int, foobar: Int, barfoo: Int) +fun testtesttesttest(foofoo: Int, @Some barbar: Int, foobar: Int, barfoo: Int) + +fun testtesttesttest(@Some foofoo: Int, @Some barbar: Int, @Some foobar: Int, barfoo: Int) + fun test() { for (foo: Int in bar) { @@ -75,3 +79,8 @@ class H(sn1: SN, sn2 : SN) { constructor(sn1: SN) { } } + +class I(sn1: SN, @field:Some val sn2 : SN, sn3 : SN, sn4 : SN, sn5 : SN, sn6 : SN, sn6 : SN, sn8 : SN, sn9 : SN, sn10: SN, sn11: SN, sn12: SN, sn13: SN, sn14: SN) { + constructor(sn1: SN, sn2 : SN, sn3 : SN, @Some sn4 : SN, sn5 : SN, sn6 : SN, sn6 : SN, sn8 : SN, sn9 : SN, sn10: SN, sn11: SN, sn12: SN, sn13: SN, sn14: SN) { + } +}