From 96a11707ca5b10a03aaf05369f0260ba1876b27a Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Fri, 27 Dec 2019 19:32:08 +0700 Subject: [PATCH] Formatter: support trailing comma in lambda value parameters & fix comments in `KtParameter` #KT-34744 --- .../idea/formatter/KotlinCommonBlock.kt | 1 + .../TrailingCommaPostFormatProcessor.kt | 66 +++++++++---- .../TypeParameterList.after.inv.kt | 38 ++++++++ .../typeParameters/TypeParameterList.after.kt | 39 ++++++++ .../typeParameters/TypeParameterList.kt | 34 +++++++ .../LambdaValueParameters.after.inv.kt | 89 +++++++++++++++++ .../LambdaValueParameters.after.kt | 97 +++++++++++++++++++ .../valueParameters/LambdaValueParameters.kt | 80 +++++++++++++++ .../ParameterListChopAsNeeded.after.inv.kt | 6 +- .../ParameterListChopAsNeeded.after.kt | 8 +- .../ParameterListChopAsNeeded.kt | 2 +- .../ParameterListDoNotWrap.after.inv.kt | 6 +- .../ParameterListDoNotWrap.after.kt | 8 +- .../valueParameters/ParameterListDoNotWrap.kt | 2 +- .../ParameterListWrapAlways.after.inv.kt | 6 +- .../ParameterListWrapAlways.after.kt | 8 +- .../ParameterListWrapAlways.kt | 2 +- .../ParameterListWrapAsNeeded.after.inv.kt | 6 +- .../ParameterListWrapAsNeeded.after.kt | 8 +- .../ParameterListWrapAsNeeded.kt | 2 +- .../formatter/FormatterTestGenerated.java | 10 ++ 21 files changed, 468 insertions(+), 50 deletions(-) create mode 100644 idea/testData/formatter/trailingComma/valueParameters/LambdaValueParameters.after.inv.kt create mode 100644 idea/testData/formatter/trailingComma/valueParameters/LambdaValueParameters.after.kt create mode 100644 idea/testData/formatter/trailingComma/valueParameters/LambdaValueParameters.kt 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 79a634e94c3..996836728a3 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt @@ -609,6 +609,7 @@ abstract class KotlinCommonBlock( node.withTrailingComma, additionalWrap = trailingCommaWrappingStrategyWithMultiLineCheck(LPAR, RPAR) ) + FUNCTION_TYPE -> return defaultTrailingCommaWrappingStrategy(LPAR, RPAR) FUNCTION_LITERAL -> { if (nodePsi.parent?.safeAs()?.needTrailingComma(settings) == true) { val check = thisOrPrevIsMultiLineElement(COMMA, LBRACE /* not necessary */, ARROW /* not necessary */) diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/TrailingCommaPostFormatProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/formatter/TrailingCommaPostFormatProcessor.kt index 2ccfd3ee762..86445f5cbda 100644 --- a/idea/src/org/jetbrains/kotlin/idea/formatter/TrailingCommaPostFormatProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/TrailingCommaPostFormatProcessor.kt @@ -8,8 +8,10 @@ package org.jetbrains.kotlin.idea.formatter import com.intellij.lang.ASTNode import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.util.TextRange +import com.intellij.psi.PsiComment import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile +import com.intellij.psi.PsiWhiteSpace import com.intellij.psi.codeStyle.CodeStyleManager import com.intellij.psi.codeStyle.CodeStyleSettings import com.intellij.psi.impl.source.codeStyle.PostFormatProcessor @@ -81,8 +83,9 @@ private class TrailingCommaVisitor(val settings: CodeStyleSettings) : KtTreeVisi if (elementType === KtTokens.COMMA || parent.needComma) { // add a missing comma if (elementType !== KtTokens.COMMA) { - changePsi(parent) { element, factory -> - element.addAfter(factory.createComma(), lastElement) + changePsi(parent) { factory -> + lastElement.addCommaAfter(factory) + true } } @@ -97,31 +100,31 @@ private class TrailingCommaVisitor(val settings: CodeStyleSettings) : KtTreeVisi else -> settings.kotlinCustomSettings.ALLOW_TRAILING_COMMA && isMultiline() } - private fun changePsi(element: KtElement, update: (KtElement, KtPsiFactory) -> Unit) { + private fun changePsi(element: KtElement, update: (KtPsiFactory) -> Boolean) { val oldLength = element.textLength - update(element, KtPsiFactory(element)) - val result = CodeStyleManager.getInstance(element.project).reformat(element) - myPostProcessor.updateResultRange(oldLength, result.textLength) + if (update(KtPsiFactory(element))) { + val result = CodeStyleManager.getInstance(element.project).reformat(element) + myPostProcessor.updateResultRange(oldLength, result.textLength) + } } private fun correctCommaPosition(parent: KtElement) { val invalidElements = parent.firstChild?.siblings(withItself = false)?.mapNotNull { - if (it !is ASTNode || it.elementType != KtTokens.COMMA) return@mapNotNull null - - val prevWithComment = it.getPrevSiblingIgnoringWhitespace(false) - val prevWithoutComment = it.getPrevSiblingIgnoringWhitespaceAndComments(false) - if (prevWithoutComment?.equals(prevWithComment) == false) { - it.createSmartPointer() to prevWithoutComment.createSmartPointer() - } else - null + if (it.safeAs()?.elementType != KtTokens.COMMA) return@mapNotNull null + it.createSmartPointer() }?.toList() ?: return if (invalidElements.isNotEmpty()) { - changePsi(parent) { element, factory -> - for ((pointToComma, pointToElement) in invalidElements) { - element.addAfter(factory.createComma(), pointToElement.element) - pointToComma.element?.delete() + changePsi(parent) { factory -> + var change = false + for (pointerToComma in invalidElements) { + pointerToComma.element?.let { + if (correctComma(it, factory)) { + change = true + } + } } + change } } } @@ -146,6 +149,33 @@ private class TrailingCommaVisitor(val settings: CodeStyleSettings) : KtTreeVisi } } +private fun PsiElement.addCommaAfter(factory: KtPsiFactory) { + val comma = factory.createComma() + parent.addAfter(comma, this) +} + +private fun correctComma(comma: PsiElement, factory: KtPsiFactory): Boolean { + val prevWithComment = comma.getPrevSiblingIgnoringWhitespace(false) + val prevWithoutComment = comma.getPrevSiblingIgnoringWhitespaceAndComments(false) + return when { + prevWithoutComment?.equals(prevWithComment) == false -> { + prevWithoutComment.addCommaAfter(factory) + comma.delete() + true + } + prevWithoutComment is KtParameter -> { + val check = { element: PsiElement -> element is PsiWhiteSpace || element is PsiComment } + val lastElement = prevWithoutComment.lastChild?.takeIf(check) ?: return false + val firstElement = lastElement.siblings(forward = false, withItself = true).takeWhile(check).last() + comma.parent.addRangeAfter(firstElement, lastElement, comma) + prevWithoutComment.deleteChildRange(firstElement, lastElement) + true + } + else -> + false + } +} + private val PsiElement.lastCommaOwnerOrComma: PsiElement? get() { val lastChild = lastSignificantChild ?: return null diff --git a/idea/testData/formatter/trailingComma/typeParameters/TypeParameterList.after.inv.kt b/idea/testData/formatter/trailingComma/typeParameters/TypeParameterList.after.inv.kt index 978e83bd1c8..20c71c2cab4 100644 --- a/idea/testData/formatter/trailingComma/typeParameters/TypeParameterList.after.inv.kt +++ b/idea/testData/formatter/trailingComma/typeParameters/TypeParameterList.after.inv.kt @@ -239,4 +239,42 @@ class L< x : String, y : String, z : String > +class C< + x : Int // adad + > + +class G< + x : String, y : String, /* */ z : String // adad + > + +class G< + x : String, + y : String, + /* */ /* */ + z : String, /**/ + >() + +class H< + x : String, /* + */ + y : String, + z : String, /* + */ + > + +class J< + x : String, y : String, + z : String, /* + */ /**/ + > + +class K< + x : String, y : String, + z : String, // aw + > + +class L< + x : String, y : String, z : String //awd + > + // SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/formatter/trailingComma/typeParameters/TypeParameterList.after.kt b/idea/testData/formatter/trailingComma/typeParameters/TypeParameterList.after.kt index 5d046fbd76c..e6a3a89114c 100644 --- a/idea/testData/formatter/trailingComma/typeParameters/TypeParameterList.after.kt +++ b/idea/testData/formatter/trailingComma/typeParameters/TypeParameterList.after.kt @@ -247,4 +247,43 @@ class L< x : String, y : String, z : String, > +class C< + x : Int, // adad + > + +class G< + x : String, y : String, /* */ + z : String, // adad + > + +class G< + x : String, + y : String, + /* */ /* */ + z : String, /**/ + >() + +class H< + x : String, /* + */ + y : String, + z : String, /* + */ + > + +class J< + x : String, y : String, + z : String, /* + */ /**/ + > + +class K< + x : String, y : String, + z : String, // aw + > + +class L< + x : String, y : String, z : String, //awd + > + // SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/formatter/trailingComma/typeParameters/TypeParameterList.kt b/idea/testData/formatter/trailingComma/typeParameters/TypeParameterList.kt index 62ada0732a3..6ac1acc86ef 100644 --- a/idea/testData/formatter/trailingComma/typeParameters/TypeParameterList.kt +++ b/idea/testData/formatter/trailingComma/typeParameters/TypeParameterList.kt @@ -226,4 +226,38 @@ class L< x: String, y: String, z: String > +class C< + x: Int // adad +> + +class G< + x: String, y: String + , /* */ z: String // adad +> + +class G< + x: String, y: String + /* */, /* */ z: String /**/, +>() + +class H< + x: String, /* + */ y: String, + z: String /* + */ ,> + +class J< + x: String, y: String , z: String /* + */ + , /**/ > + +class K< + x: String, y: String, + z: String // aw + , > + +class L< + x: String, y: String, z: String //awd +> + // SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/formatter/trailingComma/valueParameters/LambdaValueParameters.after.inv.kt b/idea/testData/formatter/trailingComma/valueParameters/LambdaValueParameters.after.inv.kt new file mode 100644 index 00000000000..3a99ab882d1 --- /dev/null +++ b/idea/testData/formatter/trailingComma/valueParameters/LambdaValueParameters.after.inv.kt @@ -0,0 +1,89 @@ +fun main() { + val x: ( + y: Comparable>, + z: Iterable> // trailing comma + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>, + z: Iterable> + ) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable>) -> Int = { + 10 + } + + val x: ( + y: Comparable>, z: Iterable>, + ) -> Int = { + 10 + } + + val x: (y: Comparable>) -> Int = { + 10 + } + + val x: ( + y: Comparable>, + ) -> Int = { + 10 + } + + val x: (y: Comparable> + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>) -> Int = { + 10 + } + + val x: ( + y: Comparable>, // + z: Iterable> // /**/ + ) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable> + // wd + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>,/* + */ + z: Iterable>, /* // + */ + ) -> Int = { + 10 + } + + val x: (/**/y: Comparable>/**/) -> Int = { + 10 + } + + val x: ( + y: Comparable>,/**/ + ) -> Int = { + 10 + } + + val x: (y: Comparable> + ) -> Int = { + 10 + } + + val x: ( /* + */y: Comparable>) -> Int = { + 10 + } +} + +// SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/formatter/trailingComma/valueParameters/LambdaValueParameters.after.kt b/idea/testData/formatter/trailingComma/valueParameters/LambdaValueParameters.after.kt new file mode 100644 index 00000000000..07d0c244eb8 --- /dev/null +++ b/idea/testData/formatter/trailingComma/valueParameters/LambdaValueParameters.after.kt @@ -0,0 +1,97 @@ +fun main() { + val x: ( + y: Comparable>, + z: Iterable>, // trailing comma + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>, + z: Iterable>, + ) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable>) -> Int = { + 10 + } + + val x: ( + y: Comparable>, z: Iterable>, + ) -> Int = { + 10 + } + + val x: (y: Comparable>) -> Int = { + 10 + } + + val x: ( + y: Comparable>, + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>, + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>, + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>, // + z: Iterable>, // /**/ + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>, + z: Iterable>, + // wd + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>,/* + */ + z: Iterable>, /* // + */ + ) -> Int = { + 10 + } + + val x: (/**/y: Comparable>/**/) -> Int = { + 10 + } + + val x: ( + y: Comparable>,/**/ + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>, + ) -> Int = { + 10 + } + + val x: ( + /* + */ + y: Comparable>, + ) -> Int = { + 10 + } +} + +// SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/formatter/trailingComma/valueParameters/LambdaValueParameters.kt b/idea/testData/formatter/trailingComma/valueParameters/LambdaValueParameters.kt new file mode 100644 index 00000000000..0a120e35bbc --- /dev/null +++ b/idea/testData/formatter/trailingComma/valueParameters/LambdaValueParameters.kt @@ -0,0 +1,80 @@ +fun main() { + val x: ( + y: Comparable>, + z: Iterable> // trailing comma + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>, + z: Iterable> + ) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable>) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable>,) -> Int = { + 10 + } + + val x: (y: Comparable>) -> Int = { + 10 + } + + val x: (y: Comparable>,) -> Int = { + 10 + } + + val x: (y: Comparable> + ) -> Int = { + 10 + } + + val x: ( + y: Comparable>) -> Int = { + 10 + } + + val x: ( + y: Comparable>, // + z: Iterable> // /**/ + ) -> Int = { + 10 + } + + val x: (y: Comparable>, z: Iterable> + // wd + ) -> Int = { + 10 + } + + val x: (y: Comparable>/* + */, z: Iterable>, /* // + */) -> Int = { + 10 + } + + val x: (/**/y: Comparable>/**/) -> Int = { + 10 + } + + val x: (y: Comparable>/**/,) -> Int = { + 10 + } + + val x: (y: Comparable> + ) -> Int = { + 10 + } + + val x: ( /* + */y: Comparable>) -> Int = { + 10 + } +} + +// SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/formatter/trailingComma/valueParameters/ParameterListChopAsNeeded.after.inv.kt b/idea/testData/formatter/trailingComma/valueParameters/ParameterListChopAsNeeded.after.inv.kt index ae00476af1c..35934c0e10a 100644 --- a/idea/testData/formatter/trailingComma/valueParameters/ParameterListChopAsNeeded.after.inv.kt +++ b/idea/testData/formatter/trailingComma/valueParameters/ParameterListChopAsNeeded.after.inv.kt @@ -468,8 +468,8 @@ class H( class J( val x: String, val y: String, - val z: String /* - */, + val z: String, /* + */ ) class K( @@ -478,7 +478,7 @@ class K( ) class L( - val x: String, val y: String, val z: String + val x: String, val y: String, val z: String // adwd ) // SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/formatter/trailingComma/valueParameters/ParameterListChopAsNeeded.after.kt b/idea/testData/formatter/trailingComma/valueParameters/ParameterListChopAsNeeded.after.kt index e938f31674d..9edfc179026 100644 --- a/idea/testData/formatter/trailingComma/valueParameters/ParameterListChopAsNeeded.after.kt +++ b/idea/testData/formatter/trailingComma/valueParameters/ParameterListChopAsNeeded.after.kt @@ -462,7 +462,7 @@ class G( class G( val x: String, val y: String - = "" /* */, /* */ + = "", /* */ /* */ val z: String, ) @@ -475,8 +475,8 @@ class H( class J( val x: String, val y: String, - val z: String /* - */, + val z: String, /* + */ ) class K( @@ -485,7 +485,7 @@ class K( ) class L( - val x: String, val y: String, val z: String, + val x: String, val y: String, val z: String, // adwd ) // SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/formatter/trailingComma/valueParameters/ParameterListChopAsNeeded.kt b/idea/testData/formatter/trailingComma/valueParameters/ParameterListChopAsNeeded.kt index fa69907a190..fed6aced5c5 100644 --- a/idea/testData/formatter/trailingComma/valueParameters/ParameterListChopAsNeeded.kt +++ b/idea/testData/formatter/trailingComma/valueParameters/ParameterListChopAsNeeded.kt @@ -454,7 +454,7 @@ class K( , ) class L( - val x: String, val y: String, val z: String + val x: String, val y: String, val z: String // adwd ) // SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/formatter/trailingComma/valueParameters/ParameterListDoNotWrap.after.inv.kt b/idea/testData/formatter/trailingComma/valueParameters/ParameterListDoNotWrap.after.inv.kt index d2f643ed375..77e56e386a2 100644 --- a/idea/testData/formatter/trailingComma/valueParameters/ParameterListDoNotWrap.after.inv.kt +++ b/idea/testData/formatter/trailingComma/valueParameters/ParameterListDoNotWrap.after.inv.kt @@ -468,8 +468,8 @@ class H( class J( val x: String, val y: String, - val z: String /* - */, + val z: String, /* + */ ) class K( @@ -478,7 +478,7 @@ class K( ) class L( - val x: String, val y: String, val z: String + val x: String, val y: String, val z: String // adwd ) // SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/formatter/trailingComma/valueParameters/ParameterListDoNotWrap.after.kt b/idea/testData/formatter/trailingComma/valueParameters/ParameterListDoNotWrap.after.kt index bf34d15be63..dc57816be96 100644 --- a/idea/testData/formatter/trailingComma/valueParameters/ParameterListDoNotWrap.after.kt +++ b/idea/testData/formatter/trailingComma/valueParameters/ParameterListDoNotWrap.after.kt @@ -462,7 +462,7 @@ class G( class G( val x: String, val y: String - = "" /* */, /* */ + = "", /* */ /* */ val z: String, ) @@ -475,8 +475,8 @@ class H( class J( val x: String, val y: String, - val z: String /* - */, + val z: String, /* + */ ) class K( @@ -485,7 +485,7 @@ class K( ) class L( - val x: String, val y: String, val z: String, + val x: String, val y: String, val z: String, // adwd ) // SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/formatter/trailingComma/valueParameters/ParameterListDoNotWrap.kt b/idea/testData/formatter/trailingComma/valueParameters/ParameterListDoNotWrap.kt index bd40aeec435..1201314a17e 100644 --- a/idea/testData/formatter/trailingComma/valueParameters/ParameterListDoNotWrap.kt +++ b/idea/testData/formatter/trailingComma/valueParameters/ParameterListDoNotWrap.kt @@ -454,7 +454,7 @@ class K( , ) class L( - val x: String, val y: String, val z: String + val x: String, val y: String, val z: String // adwd ) // SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAlways.after.inv.kt b/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAlways.after.inv.kt index 70228165705..0b1445e0a06 100644 --- a/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAlways.after.inv.kt +++ b/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAlways.after.inv.kt @@ -490,8 +490,8 @@ class H( class J( val x: String, val y: String, - val z: String /* - */, + val z: String, /* + */ ) class K( @@ -503,7 +503,7 @@ class K( class L( val x: String, val y: String, - val z: String + val z: String // adwd ) // SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAlways.after.kt b/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAlways.after.kt index e8064eb9e0e..815244a547c 100644 --- a/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAlways.after.kt +++ b/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAlways.after.kt @@ -477,7 +477,7 @@ class G( class G( val x: String, val y: String - = "" /* */, /* */ + = "", /* */ /* */ val z: String, ) @@ -491,8 +491,8 @@ class H( class J( val x: String, val y: String, - val z: String /* - */, + val z: String, /* + */ ) class K( @@ -504,7 +504,7 @@ class K( class L( val x: String, val y: String, - val z: String, + val z: String, // adwd ) // SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAlways.kt b/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAlways.kt index 9a0160249b3..8d0c8dac4b2 100644 --- a/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAlways.kt +++ b/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAlways.kt @@ -454,7 +454,7 @@ class K( , ) class L( - val x: String, val y: String, val z: String + val x: String, val y: String, val z: String // adwd ) // SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAsNeeded.after.inv.kt b/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAsNeeded.after.inv.kt index 56e5ac3baf8..da7f6646487 100644 --- a/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAsNeeded.after.inv.kt +++ b/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAsNeeded.after.inv.kt @@ -468,8 +468,8 @@ class H( class J( val x: String, val y: String, - val z: String /* - */, + val z: String, /* + */ ) class K( @@ -478,7 +478,7 @@ class K( ) class L( - val x: String, val y: String, val z: String + val x: String, val y: String, val z: String // adwd ) // SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAsNeeded.after.kt b/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAsNeeded.after.kt index 492dae389a4..b8506d98db6 100644 --- a/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAsNeeded.after.kt +++ b/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAsNeeded.after.kt @@ -462,7 +462,7 @@ class G( class G( val x: String, val y: String - = "" /* */, /* */ + = "", /* */ /* */ val z: String, ) @@ -475,8 +475,8 @@ class H( class J( val x: String, val y: String, - val z: String /* - */, + val z: String, /* + */ ) class K( @@ -485,7 +485,7 @@ class K( ) class L( - val x: String, val y: String, val z: String, + val x: String, val y: String, val z: String, // adwd ) // SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAsNeeded.kt b/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAsNeeded.kt index da1b798d385..21cc5933cfe 100644 --- a/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAsNeeded.kt +++ b/idea/testData/formatter/trailingComma/valueParameters/ParameterListWrapAsNeeded.kt @@ -454,7 +454,7 @@ class K( , ) class L( - val x: String, val y: String, val z: String + val x: String, val y: String, val z: String // adwd ) // SET_TRUE: ALLOW_TRAILING_COMMA diff --git a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java index e86aa498a72..7369b76b295 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java @@ -1299,6 +1299,11 @@ public class FormatterTestGenerated extends AbstractFormatterTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/formatter/trailingComma/valueParameters"), Pattern.compile("^([^\\.]+)\\.after\\.kt.*$"), null, true); } + @TestMetadata("LambdaValueParameters.after.kt") + public void testLambdaValueParameters() throws Exception { + runTest("idea/testData/formatter/trailingComma/valueParameters/LambdaValueParameters.after.kt"); + } + @TestMetadata("ParameterListChopAsNeeded.after.kt") public void testParameterListChopAsNeeded() throws Exception { runTest("idea/testData/formatter/trailingComma/valueParameters/ParameterListChopAsNeeded.after.kt"); @@ -1851,6 +1856,11 @@ public class FormatterTestGenerated extends AbstractFormatterTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/formatter/trailingComma/valueParameters"), Pattern.compile("^([^\\.]+)\\.after\\.inv\\.kt.*$"), null, true); } + @TestMetadata("LambdaValueParameters.after.inv.kt") + public void testLambdaValueParameters() throws Exception { + runTest("idea/testData/formatter/trailingComma/valueParameters/LambdaValueParameters.after.inv.kt"); + } + @TestMetadata("ParameterListChopAsNeeded.after.inv.kt") public void testParameterListChopAsNeeded() throws Exception { runTest("idea/testData/formatter/trailingComma/valueParameters/ParameterListChopAsNeeded.after.inv.kt");