diff --git a/idea/resources/META-INF/plugin-common.xml b/idea/resources/META-INF/plugin-common.xml index e5fa8dbeda9..3b3ae2a2de9 100644 --- a/idea/resources/META-INF/plugin-common.xml +++ b/idea/resources/META-INF/plugin-common.xml @@ -1340,6 +1340,11 @@ Kotlin + + org.jetbrains.kotlin.idea.intentions.TrailingCommaIntention + Kotlin + + org.jetbrains.kotlin.idea.intentions.ToOrdinaryStringLiteralIntention Kotlin diff --git a/idea/resources/intentionDescriptions/TrailingCommaIntention/after.kt.template b/idea/resources/intentionDescriptions/TrailingCommaIntention/after.kt.template new file mode 100644 index 00000000000..f320addd493 --- /dev/null +++ b/idea/resources/intentionDescriptions/TrailingCommaIntention/after.kt.template @@ -0,0 +1,4 @@ +fun a( + i: Int, + b: Int, +) = Unit \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/TrailingCommaIntention/before.kt.template b/idea/resources/intentionDescriptions/TrailingCommaIntention/before.kt.template new file mode 100644 index 00000000000..3120e700023 --- /dev/null +++ b/idea/resources/intentionDescriptions/TrailingCommaIntention/before.kt.template @@ -0,0 +1,4 @@ +fun a( + i: Int, + b: Int +) = Unit \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/TrailingCommaIntention/description.html b/idea/resources/intentionDescriptions/TrailingCommaIntention/description.html new file mode 100644 index 00000000000..dfdaae8fdc2 --- /dev/null +++ b/idea/resources/intentionDescriptions/TrailingCommaIntention/description.html @@ -0,0 +1,5 @@ + + +This intention changes the setting Editor -> Code Style -> Kotlin -> Wrapping and Braces -> Use trailing comma. + + \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/TrailingCommaIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/TrailingCommaIntention.kt new file mode 100644 index 00000000000..7af1c21f10b --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/TrailingCommaIntention.kt @@ -0,0 +1,28 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.intentions + +import com.intellij.application.options.CodeStyle +import com.intellij.codeInsight.intention.LowPriorityAction +import com.intellij.openapi.editor.Editor +import org.jetbrains.kotlin.idea.formatter.kotlinCustomSettings +import org.jetbrains.kotlin.idea.util.addTrailingCommaIsAllowedForThis +import org.jetbrains.kotlin.psi.KtElement + +class TrailingCommaIntention : SelfTargetingIntention(KtElement::class.java, "Enable/disable a trailing comma in the formatter"), + LowPriorityAction { + override fun applyTo(element: KtElement, editor: Editor?) { + val kotlinCustomSettings = CodeStyle.getSettings(element.project).kotlinCustomSettings + kotlinCustomSettings.ALLOW_TRAILING_COMMA = !kotlinCustomSettings.ALLOW_TRAILING_COMMA + } + + override fun isApplicableTo(element: KtElement, caretOffset: Int): Boolean { + return element.addTrailingCommaIsAllowedForThis().also { + val action = if (CodeStyle.getSettings(element.project).kotlinCustomSettings.ALLOW_TRAILING_COMMA) "Disable" else "Enable" + text = "$action a trailing comma by default in the formatter" + } + } +} \ No newline at end of file diff --git a/idea/testData/intentions/trailingComma/.intention b/idea/testData/intentions/trailingComma/.intention new file mode 100644 index 00000000000..78d9863a346 --- /dev/null +++ b/idea/testData/intentions/trailingComma/.intention @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.intentions.TrailingCommaIntention diff --git a/idea/testData/intentions/trailingComma/valueParameterList.kt b/idea/testData/intentions/trailingComma/valueParameterList.kt new file mode 100644 index 00000000000..813ce9f2f15 --- /dev/null +++ b/idea/testData/intentions/trailingComma/valueParameterList.kt @@ -0,0 +1 @@ +fun a(i: Int) = Unit \ No newline at end of file diff --git a/idea/testData/intentions/trailingComma/valueParameterList.kt.after b/idea/testData/intentions/trailingComma/valueParameterList.kt.after new file mode 100644 index 00000000000..813ce9f2f15 --- /dev/null +++ b/idea/testData/intentions/trailingComma/valueParameterList.kt.after @@ -0,0 +1 @@ +fun a(i: Int) = Unit \ No newline at end of file diff --git a/idea/testData/multiModuleQuickFix/other/importExpectClassWithoutActualInJvm/jvm/b.kt b/idea/testData/multiModuleQuickFix/other/importExpectClassWithoutActualInJvm/jvm/b.kt index 241d17151bf..e437490a3bb 100644 --- a/idea/testData/multiModuleQuickFix/other/importExpectClassWithoutActualInJvm/jvm/b.kt +++ b/idea/testData/multiModuleQuickFix/other/importExpectClassWithoutActualInJvm/jvm/b.kt @@ -4,6 +4,7 @@ // ACTION: Create enum 'Foo' // ACTION: Create interface 'Foo' // ACTION: Create type parameter 'Foo' in function 'use' +// ACTION: Enable a trailing comma by default in the formatter // ERROR: Unresolved reference: Foo package bar diff --git a/idea/testData/multiModuleQuickFix/other/importExpectClassWithoutActualInJvm/jvm/b.kt.after b/idea/testData/multiModuleQuickFix/other/importExpectClassWithoutActualInJvm/jvm/b.kt.after index c0dfe6a4c40..4b9b457d558 100644 --- a/idea/testData/multiModuleQuickFix/other/importExpectClassWithoutActualInJvm/jvm/b.kt.after +++ b/idea/testData/multiModuleQuickFix/other/importExpectClassWithoutActualInJvm/jvm/b.kt.after @@ -4,6 +4,7 @@ // ACTION: Create enum 'Foo' // ACTION: Create interface 'Foo' // ACTION: Create type parameter 'Foo' in function 'use' +// ACTION: Enable a trailing comma by default in the formatter // ERROR: Unresolved reference: Foo package bar diff --git a/idea/testData/quickfix/addDataModifier/abstract.kt b/idea/testData/quickfix/addDataModifier/abstract.kt index 5c795d6a1be..77a97ccf5f8 100644 --- a/idea/testData/quickfix/addDataModifier/abstract.kt +++ b/idea/testData/quickfix/addDataModifier/abstract.kt @@ -3,6 +3,7 @@ // ACTION: Create extension function 'Foo.component2' // ACTION: Create member function 'Foo.component1' // ACTION: Create member function 'Foo.component2' +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Put arguments on separate lines // ERROR: Cannot create an instance of an abstract class // ERROR: Destructuring declaration initializer of type Foo must have a 'component1()' function diff --git a/idea/testData/quickfix/addDataModifier/inner.kt b/idea/testData/quickfix/addDataModifier/inner.kt index f7bac564dc3..6f83810dcf9 100644 --- a/idea/testData/quickfix/addDataModifier/inner.kt +++ b/idea/testData/quickfix/addDataModifier/inner.kt @@ -3,6 +3,7 @@ // ACTION: Create extension function 'Test.Foo.component2' // ACTION: Create member function 'Test.Foo.component1' // ACTION: Create member function 'Test.Foo.component2' +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Put arguments on separate lines // ERROR: Destructuring declaration initializer of type Test.Foo must have a 'component1()' function // ERROR: Destructuring declaration initializer of type Test.Foo must have a 'component2()' function diff --git a/idea/testData/quickfix/addDataModifier/invisibleParameter.kt b/idea/testData/quickfix/addDataModifier/invisibleParameter.kt index 02f99688ce9..d3d4069c878 100644 --- a/idea/testData/quickfix/addDataModifier/invisibleParameter.kt +++ b/idea/testData/quickfix/addDataModifier/invisibleParameter.kt @@ -3,6 +3,7 @@ // ACTION: Create extension function 'Foo.component2' // ACTION: Create member function 'Foo.component1' // ACTION: Create member function 'Foo.component2' +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Put arguments on separate lines // ERROR: Destructuring declaration initializer of type Foo must have a 'component1()' function // ERROR: Destructuring declaration initializer of type Foo must have a 'component2()' function diff --git a/idea/testData/quickfix/addDataModifier/invisibleParameter2.kt b/idea/testData/quickfix/addDataModifier/invisibleParameter2.kt index de64d29e965..ae1be211bb3 100644 --- a/idea/testData/quickfix/addDataModifier/invisibleParameter2.kt +++ b/idea/testData/quickfix/addDataModifier/invisibleParameter2.kt @@ -3,6 +3,7 @@ // ACTION: Create extension function 'Foo.component2' // ACTION: Create member function 'Foo.component1' // ACTION: Create member function 'Foo.component2' +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Put arguments on separate lines // ERROR: Destructuring declaration initializer of type Foo must have a 'component1()' function // ERROR: Destructuring declaration initializer of type Foo must have a 'component2()' function diff --git a/idea/testData/quickfix/addDataModifier/noParameter.kt b/idea/testData/quickfix/addDataModifier/noParameter.kt index 0dea8fafcef..49f2dab27de 100644 --- a/idea/testData/quickfix/addDataModifier/noParameter.kt +++ b/idea/testData/quickfix/addDataModifier/noParameter.kt @@ -3,6 +3,7 @@ // ACTION: Create extension function 'Foo.component2' // ACTION: Create member function 'Foo.component1' // ACTION: Create member function 'Foo.component2' +// ACTION: Enable a trailing comma by default in the formatter // ERROR: Destructuring declaration initializer of type Foo must have a 'component1()' function // ERROR: Destructuring declaration initializer of type Foo must have a 'component2()' function class Foo() diff --git a/idea/testData/quickfix/addDataModifier/notVarVal.kt b/idea/testData/quickfix/addDataModifier/notVarVal.kt index f456180ae3c..8ddfa07e1de 100644 --- a/idea/testData/quickfix/addDataModifier/notVarVal.kt +++ b/idea/testData/quickfix/addDataModifier/notVarVal.kt @@ -3,6 +3,7 @@ // ACTION: Create extension function 'Foo.component2' // ACTION: Create member function 'Foo.component1' // ACTION: Create member function 'Foo.component2' +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Put arguments on separate lines // ERROR: Destructuring declaration initializer of type Foo must have a 'component1()' function // ERROR: Destructuring declaration initializer of type Foo must have a 'component2()' function diff --git a/idea/testData/quickfix/addDataModifier/open.kt b/idea/testData/quickfix/addDataModifier/open.kt index e14740afc03..d1d29c6121b 100644 --- a/idea/testData/quickfix/addDataModifier/open.kt +++ b/idea/testData/quickfix/addDataModifier/open.kt @@ -3,6 +3,7 @@ // ACTION: Create extension function 'Foo.component2' // ACTION: Create member function 'Foo.component1' // ACTION: Create member function 'Foo.component2' +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Put arguments on separate lines // ERROR: Destructuring declaration initializer of type Foo must have a 'component1()' function // ERROR: Destructuring declaration initializer of type Foo must have a 'component2()' function diff --git a/idea/testData/quickfix/addDataModifier/sealed.kt b/idea/testData/quickfix/addDataModifier/sealed.kt index 8724e134c39..ef37181f075 100644 --- a/idea/testData/quickfix/addDataModifier/sealed.kt +++ b/idea/testData/quickfix/addDataModifier/sealed.kt @@ -3,6 +3,7 @@ // ACTION: Create extension function 'Foo.component2' // ACTION: Create member function 'Foo.component1' // ACTION: Create member function 'Foo.component2' +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Put arguments on separate lines // ERROR: Cannot access '': it is private in 'Foo' // ERROR: Destructuring declaration initializer of type Foo must have a 'component1()' function diff --git a/idea/testData/quickfix/addDataModifier/vararg.kt b/idea/testData/quickfix/addDataModifier/vararg.kt index ddcc7f25a73..f50d8da0bc4 100644 --- a/idea/testData/quickfix/addDataModifier/vararg.kt +++ b/idea/testData/quickfix/addDataModifier/vararg.kt @@ -3,6 +3,7 @@ // ACTION: Create extension function 'Foo.component2' // ACTION: Create member function 'Foo.component1' // ACTION: Create member function 'Foo.component2' +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Put arguments on separate lines // ERROR: Destructuring declaration initializer of type Foo must have a 'component1()' function // ERROR: Destructuring declaration initializer of type Foo must have a 'component2()' function diff --git a/idea/testData/quickfix/addInline/local.kt b/idea/testData/quickfix/addInline/local.kt index 4947f867844..1048dc5fa24 100644 --- a/idea/testData/quickfix/addInline/local.kt +++ b/idea/testData/quickfix/addInline/local.kt @@ -1,4 +1,5 @@ // "Add 'inline' to function 'foo'" "false" +// ACTION: Enable a trailing comma by default in the formatter // ERROR: Modifier 'crossinline' is allowed only for function parameters of an inline function fun bar() { diff --git a/idea/testData/quickfix/addVarianceModifier/emptyTest.kt b/idea/testData/quickfix/addVarianceModifier/emptyTest.kt index 1b5241428c6..252df4c23ab 100644 --- a/idea/testData/quickfix/addVarianceModifier/emptyTest.kt +++ b/idea/testData/quickfix/addVarianceModifier/emptyTest.kt @@ -1,3 +1,4 @@ // "Add 'out' variance" "false" +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Implement interface interface Empty<T> \ No newline at end of file diff --git a/idea/testData/quickfix/autoImports/multiDeclarationExtensionComponentNoOperator.test b/idea/testData/quickfix/autoImports/multiDeclarationExtensionComponentNoOperator.test index ac2f4d7f48e..347550e7656 100644 --- a/idea/testData/quickfix/autoImports/multiDeclarationExtensionComponentNoOperator.test +++ b/idea/testData/quickfix/autoImports/multiDeclarationExtensionComponentNoOperator.test @@ -3,6 +3,7 @@ // ERROR: Destructuring declaration initializer of type Some must have a 'component1()' function // ACTION: Create extension function 'Some.component1' // ACTION: Create member function 'Some.component1' +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Introduce import alias diff --git a/idea/testData/quickfix/changeSignature/removeUnusedParameterOfPropertySetter.kt b/idea/testData/quickfix/changeSignature/removeUnusedParameterOfPropertySetter.kt index 078d25ef04e..0864764d540 100644 --- a/idea/testData/quickfix/changeSignature/removeUnusedParameterOfPropertySetter.kt +++ b/idea/testData/quickfix/changeSignature/removeUnusedParameterOfPropertySetter.kt @@ -1,4 +1,5 @@ // "Remove parameter 'value'" "false" +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Specify type explicitly class Abacaba { var foo: String diff --git a/idea/testData/quickfix/createFromUsage/createClass/typeReference/noAnnotationForTypeBound.kt b/idea/testData/quickfix/createFromUsage/createClass/typeReference/noAnnotationForTypeBound.kt index 6f80b94d907..28086f9d97f 100644 --- a/idea/testData/quickfix/createFromUsage/createClass/typeReference/noAnnotationForTypeBound.kt +++ b/idea/testData/quickfix/createFromUsage/createClass/typeReference/noAnnotationForTypeBound.kt @@ -3,5 +3,6 @@ // ACTION: Create interface 'NotExistent' // ACTION: Create type parameter 'NotExistent' in class 'TPB' // ACTION: Create test +// ACTION: Enable a trailing comma by default in the formatter // ERROR: Unresolved reference: NotExistent class TPBNotExistent> \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createClass/typeReference/noEnumForTypeBound.kt b/idea/testData/quickfix/createFromUsage/createClass/typeReference/noEnumForTypeBound.kt index 56cbf3915d4..f5d6b644036 100644 --- a/idea/testData/quickfix/createFromUsage/createClass/typeReference/noEnumForTypeBound.kt +++ b/idea/testData/quickfix/createFromUsage/createClass/typeReference/noEnumForTypeBound.kt @@ -3,5 +3,6 @@ // ACTION: Create interface 'NotExistent' // ACTION: Create type parameter 'NotExistent' in class 'TPB' // ACTION: Create test +// ACTION: Enable a trailing comma by default in the formatter // ERROR: Unresolved reference: NotExistent class TPBNotExistent> \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createClass/typeReference/noObjectForTypeBound.kt b/idea/testData/quickfix/createFromUsage/createClass/typeReference/noObjectForTypeBound.kt index ada91a16955..7f346102cfd 100644 --- a/idea/testData/quickfix/createFromUsage/createClass/typeReference/noObjectForTypeBound.kt +++ b/idea/testData/quickfix/createFromUsage/createClass/typeReference/noObjectForTypeBound.kt @@ -3,5 +3,6 @@ // ACTION: Create interface 'NotExistent' // ACTION: Create type parameter 'NotExistent' in class 'TPB' // ACTION: Create test +// ACTION: Enable a trailing comma by default in the formatter // ERROR: Unresolved reference: NotExistent class TPBNotExistent> \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createTypeParameter/inContainingDeclaration/qualifiedType.kt b/idea/testData/quickfix/createFromUsage/createTypeParameter/inContainingDeclaration/qualifiedType.kt index 80b0dec9b84..7dea109d1bc 100644 --- a/idea/testData/quickfix/createFromUsage/createTypeParameter/inContainingDeclaration/qualifiedType.kt +++ b/idea/testData/quickfix/createFromUsage/createTypeParameter/inContainingDeclaration/qualifiedType.kt @@ -3,6 +3,7 @@ // ACTION: Create class 'X' // ACTION: Create enum 'X' // ACTION: Create interface 'X' +// ACTION: Enable a trailing comma by default in the formatter // ERROR: Unresolved reference: X class A diff --git a/idea/testData/quickfix/createFromUsage/createTypeParameter/inContainingDeclaration/typeQualifier.kt b/idea/testData/quickfix/createFromUsage/createTypeParameter/inContainingDeclaration/typeQualifier.kt index 344487f1265..096c3bb61be 100644 --- a/idea/testData/quickfix/createFromUsage/createTypeParameter/inContainingDeclaration/typeQualifier.kt +++ b/idea/testData/quickfix/createFromUsage/createTypeParameter/inContainingDeclaration/typeQualifier.kt @@ -3,6 +3,7 @@ // ACTION: Create enum 'X' // ACTION: Create interface 'X' // ACTION: Create object 'X' +// ACTION: Enable a trailing comma by default in the formatter // ERROR: Unresolved reference: X class A diff --git a/idea/testData/quickfix/createFromUsage/createTypeParameter/inContainingDeclaration/withTypeArguments.kt b/idea/testData/quickfix/createFromUsage/createTypeParameter/inContainingDeclaration/withTypeArguments.kt index ecca6957ac9..85fee88b2d3 100644 --- a/idea/testData/quickfix/createFromUsage/createTypeParameter/inContainingDeclaration/withTypeArguments.kt +++ b/idea/testData/quickfix/createFromUsage/createTypeParameter/inContainingDeclaration/withTypeArguments.kt @@ -1,6 +1,7 @@ // "Create type parameter 'X'" "false" // ACTION: Create class 'X' // ACTION: Create interface 'X' +// ACTION: Enable a trailing comma by default in the formatter // ERROR: Unresolved reference: X class A diff --git a/idea/testData/quickfix/createFromUsage/createTypeParameter/inReferencedDeclaration/missingArguments.kt b/idea/testData/quickfix/createFromUsage/createTypeParameter/inReferencedDeclaration/missingArguments.kt index 9941dfd140e..e753e12beea 100644 --- a/idea/testData/quickfix/createFromUsage/createTypeParameter/inReferencedDeclaration/missingArguments.kt +++ b/idea/testData/quickfix/createFromUsage/createTypeParameter/inReferencedDeclaration/missingArguments.kt @@ -1,4 +1,5 @@ // "Create type parameter in class 'X'" "false" +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Introduce import alias // ERROR: 2 type arguments expected for class X class X diff --git a/idea/testData/quickfix/createFromUsage/createTypeParameter/inReferencedDeclaration/notOnTypeArgumentList.kt b/idea/testData/quickfix/createFromUsage/createTypeParameter/inReferencedDeclaration/notOnTypeArgumentList.kt index 5e26200960a..2028958cf5a 100644 --- a/idea/testData/quickfix/createFromUsage/createTypeParameter/inReferencedDeclaration/notOnTypeArgumentList.kt +++ b/idea/testData/quickfix/createFromUsage/createTypeParameter/inReferencedDeclaration/notOnTypeArgumentList.kt @@ -1,4 +1,5 @@ // "Create type parameter in class 'X'" "false" +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Introduce import alias // ERROR: No type arguments expected for class X diff --git a/idea/testData/quickfix/createFromUsage/createVariable/localVariable/inAnnotation.kt b/idea/testData/quickfix/createFromUsage/createVariable/localVariable/inAnnotation.kt index 717ed3c8f57..611c8993259 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/localVariable/inAnnotation.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/localVariable/inAnnotation.kt @@ -1,6 +1,7 @@ // "Create local variable 'defaultPreferencesName'" "false" // ACTION: Create parameter 'defaultPreferencesName' // ACTION: Create property 'defaultPreferencesName' +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Rename reference // ERROR: Unresolved reference: defaultPreferencesName // ERROR: Default value of annotation parameter must be a compile-time constant diff --git a/idea/testData/quickfix/createFromUsage/createVariable/parameter/dataClassPropertyByDestructuringEntryWithSkippedIndex.kt b/idea/testData/quickfix/createFromUsage/createVariable/parameter/dataClassPropertyByDestructuringEntryWithSkippedIndex.kt index 5768b59800b..bee55275b30 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/parameter/dataClassPropertyByDestructuringEntryWithSkippedIndex.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/parameter/dataClassPropertyByDestructuringEntryWithSkippedIndex.kt @@ -1,5 +1,6 @@ // "Create property 'address2' as constructor parameter" "false" // ACTION: Create property 'address' as constructor parameter +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Introduce import alias // ACTION: Make 'Person' data class // ERROR: Destructuring declaration initializer of type Person must have a 'component3()' function diff --git a/idea/testData/quickfix/decreaseVisibility/exposedParameterType.kt b/idea/testData/quickfix/decreaseVisibility/exposedParameterType.kt index 97cc116023c..54bdcb5bfc9 100644 --- a/idea/testData/quickfix/decreaseVisibility/exposedParameterType.kt +++ b/idea/testData/quickfix/decreaseVisibility/exposedParameterType.kt @@ -1,5 +1,6 @@ // "Make 'foo' private" "false" // ACTION: Convert parameter to receiver +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Make 'Nested' internal // ACTION: Make 'Nested' public // ACTION: Remove parameter 'arg' diff --git a/idea/testData/quickfix/decreaseVisibility/exposedTypeInAnnotation.kt b/idea/testData/quickfix/decreaseVisibility/exposedTypeInAnnotation.kt index c24f803911b..fc9920ff2c4 100644 --- a/idea/testData/quickfix/decreaseVisibility/exposedTypeInAnnotation.kt +++ b/idea/testData/quickfix/decreaseVisibility/exposedTypeInAnnotation.kt @@ -1,5 +1,6 @@ // "Make '' internal" "false" // DISABLE-ERRORS +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Introduce import alias // ACTION: Make 'My' public diff --git a/idea/testData/quickfix/experimental/override.kt b/idea/testData/quickfix/experimental/override.kt index 99408bcb980..16f2cab7226 100644 --- a/idea/testData/quickfix/experimental/override.kt +++ b/idea/testData/quickfix/experimental/override.kt @@ -5,6 +5,7 @@ // ACTION: Add '@OptIn(MyExperimentalAPI::class)' annotation to 'foo' // ACTION: Add '@OptIn(MyExperimentalAPI::class)' annotation to containing class 'Derived' // ACTION: Add '-Xopt-in=MyExperimentalAPI' to module light_idea_test_case compiler arguments +// ACTION: Enable a trailing comma by default in the formatter // ERROR: This declaration overrides experimental member of supertype 'Base' and must be annotated with '@MyExperimentalAPI' @RequiresOptIn diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasComment.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasComment.kt index a8d319106ae..6be58a2cea6 100644 --- a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasComment.kt +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasComment.kt @@ -2,6 +2,7 @@ // TOOL: org.jetbrains.kotlin.idea.inspections.FunctionWithLambdaExpressionBodyInspection // ACTION: Convert to block body // ACTION: Convert to run { ... } +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Specify explicit lambda signature // ACTION: Specify explicit lambda signature // ACTION: Specify return type explicitly diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasMultiStatements.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasMultiStatements.kt index 7bab8afb6ec..5d64050e91a 100644 --- a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasMultiStatements.kt +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasMultiStatements.kt @@ -3,6 +3,7 @@ // ACTION: Convert to block body // ACTION: Convert to run { ... } // ACTION: Specify explicit lambda signature +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Specify explicit lambda signature // ACTION: Specify return type explicitly fun test(a: Int, b: Int) = { diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasNoStatement.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasNoStatement.kt index 33f1928684c..af59e83a05a 100644 --- a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasNoStatement.kt +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/functionHasNoStatement.kt @@ -3,6 +3,7 @@ // ACTION: Convert to block body // ACTION: Convert to multi-line lambda // ACTION: Convert to run { ... } +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Specify explicit lambda signature // ACTION: Specify explicit lambda signature // ACTION: Specify return type explicitly diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/funtionIsUsed.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/funtionIsUsed.kt index b6a2c74c3d2..d2e751aa7b4 100644 --- a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/funtionIsUsed.kt +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/funtionIsUsed.kt @@ -2,6 +2,7 @@ // TOOL: org.jetbrains.kotlin.idea.inspections.FunctionWithLambdaExpressionBodyInspection // ACTION: Convert to block body // ACTION: Convert to multi-line lambda +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Specify explicit lambda signature // ACTION: Specify explicit lambda signature // ACTION: Specify return type explicitly diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasComment.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasComment.kt index 145160599b7..d1439f531b0 100644 --- a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasComment.kt +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasComment.kt @@ -3,6 +3,7 @@ // ACTION: Convert property getter to initializer // ACTION: Convert to block body // ACTION: Convert to run { ... } +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Specify explicit lambda signature // ACTION: Specify explicit lambda signature // ACTION: Specify type explicitly diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasMultiStatements.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasMultiStatements.kt index c84705689f3..295822e6faf 100644 --- a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasMultiStatements.kt +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasMultiStatements.kt @@ -3,6 +3,7 @@ // ACTION: Convert property getter to initializer // ACTION: Convert to block body // ACTION: Convert to run { ... } +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Specify explicit lambda signature // ACTION: Specify explicit lambda signature // ACTION: Specify type explicitly diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasNoStatement.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasNoStatement.kt index 1b25c5cb7bb..5f5abcb5d21 100644 --- a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasNoStatement.kt +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterHasNoStatement.kt @@ -4,6 +4,7 @@ // ACTION: Convert to block body // ACTION: Convert to multi-line lambda // ACTION: Convert to run { ... } +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Specify explicit lambda signature // ACTION: Specify explicit lambda signature // ACTION: Specify type explicitly diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterIsUsed.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterIsUsed.kt index 98b0b8b1906..9f6d8ac475d 100644 --- a/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterIsUsed.kt +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/removeBraces/getterIsUsed.kt @@ -3,6 +3,7 @@ // ACTION: Convert property getter to initializer // ACTION: Convert to block body // ACTION: Convert to multi-line lambda +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Specify explicit lambda signature // ACTION: Specify explicit lambda signature // ACTION: Specify type explicitly diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun/funtionIsUsed.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun/funtionIsUsed.kt index 870a778332c..fcf3e61751f 100644 --- a/idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun/funtionIsUsed.kt +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun/funtionIsUsed.kt @@ -2,6 +2,7 @@ // TOOL: org.jetbrains.kotlin.idea.inspections.FunctionWithLambdaExpressionBodyInspection // ACTION: Convert to block body // ACTION: Convert to multi-line lambda +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Specify explicit lambda signature // ACTION: Specify explicit lambda signature // ACTION: Specify return type explicitly diff --git a/idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun/getterIsUsed.kt b/idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun/getterIsUsed.kt index d0cd4b85a64..c52174841e1 100644 --- a/idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun/getterIsUsed.kt +++ b/idea/testData/quickfix/functionWithLambdaExpressionBody/wrapRun/getterIsUsed.kt @@ -3,6 +3,7 @@ // ACTION: Convert property getter to initializer // ACTION: Convert to block body // ACTION: Convert to multi-line lambda +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Specify explicit lambda signature // ACTION: Specify explicit lambda signature // ACTION: Specify type explicitly diff --git a/idea/testData/quickfix/makePrivateAndOverrideMember/parameterHasInternal.before.Main.kt b/idea/testData/quickfix/makePrivateAndOverrideMember/parameterHasInternal.before.Main.kt index 9987f55d1e8..143c9d91c3d 100644 --- a/idea/testData/quickfix/makePrivateAndOverrideMember/parameterHasInternal.before.Main.kt +++ b/idea/testData/quickfix/makePrivateAndOverrideMember/parameterHasInternal.before.Main.kt @@ -2,6 +2,7 @@ // DISABLE-ERRORS // ACTION: Convert to secondary constructor // ACTION: Create test +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Make private // ACTION: Make protected // ACTION: Make public diff --git a/idea/testData/quickfix/memberVisibilityCanBePrivate/getter.before.Main.kt b/idea/testData/quickfix/memberVisibilityCanBePrivate/getter.before.Main.kt index 8e0fde97a0b..80e2d21a35e 100644 --- a/idea/testData/quickfix/memberVisibilityCanBePrivate/getter.before.Main.kt +++ b/idea/testData/quickfix/memberVisibilityCanBePrivate/getter.before.Main.kt @@ -1,6 +1,7 @@ // "Add 'private' modifier" "false" // ACTION: Convert to secondary constructor // ACTION: Create test +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Move to class body class My(val parameter: Int) { diff --git a/idea/testData/quickfix/modifiers/addOpenToClassDeclaration/finalJavaUpperBound.before.Main.kt b/idea/testData/quickfix/modifiers/addOpenToClassDeclaration/finalJavaUpperBound.before.Main.kt index 2e889cd28d1..bf56f1bf186 100644 --- a/idea/testData/quickfix/modifiers/addOpenToClassDeclaration/finalJavaUpperBound.before.Main.kt +++ b/idea/testData/quickfix/modifiers/addOpenToClassDeclaration/finalJavaUpperBound.before.Main.kt @@ -1,5 +1,6 @@ // "class org.jetbrains.kotlin.idea.quickfix.AddModifierFix" "false" // ACTION: Create test +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Inline type parameter // ACTION: Introduce import alias // ACTION: Remove final upper bound diff --git a/idea/testData/quickfix/nullables/unsafeInfixCall/unsafeComparisonInWhen.kt b/idea/testData/quickfix/nullables/unsafeInfixCall/unsafeComparisonInWhen.kt index 4039834c10f..6e3023d88b8 100644 --- a/idea/testData/quickfix/nullables/unsafeInfixCall/unsafeComparisonInWhen.kt +++ b/idea/testData/quickfix/nullables/unsafeInfixCall/unsafeComparisonInWhen.kt @@ -1,6 +1,7 @@ // "Replace with safe (?.) call" "false" // ACTION: Add non-null asserted (!!) call // ACTION: Flip '<=' +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Replace overloaded operator with function call // ERROR: Operator call corresponds to a dot-qualified call 'w?.x.compareTo(42)' which is not allowed on a nullable receiver 'w?.x'. diff --git a/idea/testData/quickfix/platformTypesInspection/nestedNoAssertRuntime.kt b/idea/testData/quickfix/platformTypesInspection/nestedNoAssertRuntime.kt index b32956195ee..33fc1f731ed 100644 --- a/idea/testData/quickfix/platformTypesInspection/nestedNoAssertRuntime.kt +++ b/idea/testData/quickfix/platformTypesInspection/nestedNoAssertRuntime.kt @@ -2,6 +2,7 @@ // ACTION: Convert function to property // ACTION: Convert to block body // ACTION: Create test +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Specify return type explicitly fun foo() = arrayOf(java.lang.String.valueOf(1)) \ No newline at end of file diff --git a/idea/testData/quickfix/removeSingleLambdaParameter/multiple.kt b/idea/testData/quickfix/removeSingleLambdaParameter/multiple.kt index 218384b1eb9..c7f26815c64 100644 --- a/idea/testData/quickfix/removeSingleLambdaParameter/multiple.kt +++ b/idea/testData/quickfix/removeSingleLambdaParameter/multiple.kt @@ -5,6 +5,7 @@ // ACTION: Specify type explicitly // ACTION: Convert to anonymous function // ACTION: Convert to multi-line lambda +// ACTION: Enable a trailing comma by default in the formatter // RUNTIME_WITH_FULL_JDK fun main() { diff --git a/idea/testData/quickfix/removeSingleLambdaParameter/propertyWithImplicitType.kt b/idea/testData/quickfix/removeSingleLambdaParameter/propertyWithImplicitType.kt index 77f0331265f..5fd71ba5047 100644 --- a/idea/testData/quickfix/removeSingleLambdaParameter/propertyWithImplicitType.kt +++ b/idea/testData/quickfix/removeSingleLambdaParameter/propertyWithImplicitType.kt @@ -4,6 +4,7 @@ // ACTION: Convert to also // ACTION: Convert to apply // ACTION: Convert to multi-line lambda +// ACTION: Enable a trailing comma by default in the formatter fun test() { val f = { i: Int -> foo() } bar(f) diff --git a/idea/testData/quickfix/renameToUnderscore/functionExpressionParameterNoRemoveParameter.kt b/idea/testData/quickfix/renameToUnderscore/functionExpressionParameterNoRemoveParameter.kt index 700a62bbd29..4049eba5def 100644 --- a/idea/testData/quickfix/renameToUnderscore/functionExpressionParameterNoRemoveParameter.kt +++ b/idea/testData/quickfix/renameToUnderscore/functionExpressionParameterNoRemoveParameter.kt @@ -3,6 +3,7 @@ // ACTION: Convert parameter to receiver // ACTION: Rename to _ // ACTION: Specify return type explicitly +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Put parameters on separate lines fun foo(block: (String, Int) -> Unit) { diff --git a/idea/testData/quickfix/renameToUnderscore/lambdaParameterNoRemoveParameter.kt b/idea/testData/quickfix/renameToUnderscore/lambdaParameterNoRemoveParameter.kt index 6cb8a9afc24..db0a94f58a7 100644 --- a/idea/testData/quickfix/renameToUnderscore/lambdaParameterNoRemoveParameter.kt +++ b/idea/testData/quickfix/renameToUnderscore/lambdaParameterNoRemoveParameter.kt @@ -1,4 +1,5 @@ // "Remove parameter 'x'" "false" +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Move lambda argument into parentheses // ACTION: Remove explicit lambda parameter types (may break code) // ACTION: Rename to _ diff --git a/idea/testData/quickfix/renameToUnderscore/noActionForCommonFunction.kt b/idea/testData/quickfix/renameToUnderscore/noActionForCommonFunction.kt index f48a8e640b4..a31b061bf99 100644 --- a/idea/testData/quickfix/renameToUnderscore/noActionForCommonFunction.kt +++ b/idea/testData/quickfix/renameToUnderscore/noActionForCommonFunction.kt @@ -1,5 +1,6 @@ // "Rename to _" "false" // ACTION: Convert parameter to receiver +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Remove parameter 'x' fun foo(x: Int) { diff --git a/idea/testData/quickfix/renameUnresolvedReference/typeRef.kt b/idea/testData/quickfix/renameUnresolvedReference/typeRef.kt index 420b2e10dfc..a27058af459 100644 --- a/idea/testData/quickfix/renameUnresolvedReference/typeRef.kt +++ b/idea/testData/quickfix/renameUnresolvedReference/typeRef.kt @@ -3,6 +3,7 @@ // ACTION: Create class 'X' // ACTION: Create enum 'X' // ACTION: Create interface 'X' +// ACTION: Enable a trailing comma by default in the formatter // ERROR: Unresolved reference: X // ERROR: Unresolved reference: X class A { diff --git a/idea/testData/quickfix/replaceWithSafeCallForScopeFunction/letWithWrongImplicitThis.kt b/idea/testData/quickfix/replaceWithSafeCallForScopeFunction/letWithWrongImplicitThis.kt index 4d39e91a634..5e5a0c5f3f7 100644 --- a/idea/testData/quickfix/replaceWithSafeCallForScopeFunction/letWithWrongImplicitThis.kt +++ b/idea/testData/quickfix/replaceWithSafeCallForScopeFunction/letWithWrongImplicitThis.kt @@ -7,6 +7,7 @@ // ACTION: Specify explicit lambda signature // ACTION: Add return@let // ACTION: Convert to single-line lambda +// ACTION: Enable a trailing comma by default in the formatter // ERROR: Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type String? fun String?.foo(a: String?) { diff --git a/idea/testData/quickfix/specifyOverrideExplicitly/notPossible.kt b/idea/testData/quickfix/specifyOverrideExplicitly/notPossible.kt index b73b4c26835..589615d218b 100644 --- a/idea/testData/quickfix/specifyOverrideExplicitly/notPossible.kt +++ b/idea/testData/quickfix/specifyOverrideExplicitly/notPossible.kt @@ -2,6 +2,7 @@ // ACTION: Create test // ACTION: Make primary constructor internal // ACTION: Make primary constructor private +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Extract 'C' from current file // ACTION: Rename file to C.kt diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/dontChangeFunctionReturnTypeToErrorType.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/dontChangeFunctionReturnTypeToErrorType.kt index aa85dc2c3e3..422234164e6 100644 --- a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/dontChangeFunctionReturnTypeToErrorType.kt +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/dontChangeFunctionReturnTypeToErrorType.kt @@ -4,6 +4,7 @@ // ACTION: Create class 'NoSuchType' // ACTION: Create enum 'NoSuchType' // ACTION: Create interface 'NoSuchType' +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Remove explicit lambda parameter types (may break code) // ACTION: Create type parameter 'NoSuchType' in function 'foo' // ERROR: Type mismatch: inferred type is ([ERROR : NoSuchType]) -> Int but Int was expected diff --git a/idea/testData/quickfix/typeOfAnnotationMember/star.kt b/idea/testData/quickfix/typeOfAnnotationMember/star.kt index 3f97a624433..a35cd8cb31b 100644 --- a/idea/testData/quickfix/typeOfAnnotationMember/star.kt +++ b/idea/testData/quickfix/typeOfAnnotationMember/star.kt @@ -1,6 +1,7 @@ // "Replace array of boxed with array of primitive" "false" // ERROR: Invalid type of annotation member // ACTION: Introduce import alias +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Put parameters on one line annotation class SuperAnnotation( val foo: Array<*>, diff --git a/idea/testData/quickfix/typeOfAnnotationMember/string.kt b/idea/testData/quickfix/typeOfAnnotationMember/string.kt index a315db6f1ed..e2344e761f9 100644 --- a/idea/testData/quickfix/typeOfAnnotationMember/string.kt +++ b/idea/testData/quickfix/typeOfAnnotationMember/string.kt @@ -1,6 +1,7 @@ // "Replace array of boxed with array of primitive" "false" // ACTION: Put parameters on one line // ACTION: Introduce import alias +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Convert to vararg parameter (may break code) annotation class SuperAnnotation( val str: Array diff --git a/idea/testData/quickfix/unusedSuppressAnnotation/notForDeprecated.kt b/idea/testData/quickfix/unusedSuppressAnnotation/notForDeprecated.kt index f41803ad2e8..9416ecbb39d 100644 --- a/idea/testData/quickfix/unusedSuppressAnnotation/notForDeprecated.kt +++ b/idea/testData/quickfix/unusedSuppressAnnotation/notForDeprecated.kt @@ -1,4 +1,5 @@ // "Suppress unused warning if annotated by 'kotlin.Deprecated'" "false" // ACTION: Create test +// ACTION: Enable a trailing comma by default in the formatter @Deprecated("") fun foo(){} diff --git a/idea/testData/quickfix/variables/removeValVarFromParameter/constructorParameter.kt b/idea/testData/quickfix/variables/removeValVarFromParameter/constructorParameter.kt index e91d14b2150..5b8eeadcc54 100644 --- a/idea/testData/quickfix/variables/removeValVarFromParameter/constructorParameter.kt +++ b/idea/testData/quickfix/variables/removeValVarFromParameter/constructorParameter.kt @@ -4,6 +4,7 @@ // ACTION: Make protected // ACTION: Create test // ACTION: Convert to secondary constructor +// ACTION: Enable a trailing comma by default in the formatter // ACTION: Move to class body class C(val x: String) { } \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 61942395dc0..9dc7f5a9352 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -16059,6 +16059,24 @@ public class IntentionTestGenerated extends AbstractIntentionTest { } } + @TestMetadata("idea/testData/intentions/trailingComma") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class TrailingComma extends AbstractIntentionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInTrailingComma() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/intentions/trailingComma"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true); + } + + @TestMetadata("valueParameterList.kt") + public void testValueParameterList() throws Exception { + runTest("idea/testData/intentions/trailingComma/valueParameterList.kt"); + } + } + @TestMetadata("idea/testData/intentions/underscoresInNumericLiteral") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)