From 8d6d228bb85496f2433b1d971c80a96d8c42a27c Mon Sep 17 00:00:00 2001 From: nd Date: Wed, 24 May 2017 14:58:30 +0200 Subject: [PATCH] Move property to constructor preserves vararg keyword (#1095) #KT-18035 Fixed --- .../idea/intentions/MovePropertyToConstructorIntention.kt | 2 ++ .../quickfix/canBePrimaryConstructorProperty/vararg.kt | 4 ++++ .../canBePrimaryConstructorProperty/vararg.kt.after | 3 +++ .../kotlin/idea/quickfix/QuickFixTestGenerated.java | 6 ++++++ 4 files changed, 15 insertions(+) create mode 100644 idea/testData/quickfix/canBePrimaryConstructorProperty/vararg.kt create mode 100644 idea/testData/quickfix/canBePrimaryConstructorProperty/vararg.kt.after diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToConstructorIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToConstructorIntention.kt index 185582ffa11..8387208156f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToConstructorIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToConstructorIntention.kt @@ -32,6 +32,7 @@ import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor import org.jetbrains.kotlin.idea.util.CommentSaver import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers import org.jetbrains.kotlin.lexer.KtModifierKeywordToken +import org.jetbrains.kotlin.lexer.KtTokens.VARARG_KEYWORD import org.jetbrains.kotlin.lexer.KtTokens.LATEINIT_KEYWORD import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType @@ -86,6 +87,7 @@ class MovePropertyToConstructorIntention : element.modifierList?.getModifiersText()?.let(this::append) propertyAnnotationsText?.takeIf(String::isNotBlank)?.let { appendWithSpaceBefore(it) } parameterAnnotationsText?.let { appendWithSpaceBefore(it) } + if (constructorParameter.isVarArg) appendWithSpaceBefore(VARARG_KEYWORD.value) appendWithSpaceBefore(element.valOrVarKeyword.text) element.name?.let { appendWithSpaceBefore(it) } constructorParameter.typeReference?.text?.let { append(": $it") } diff --git a/idea/testData/quickfix/canBePrimaryConstructorProperty/vararg.kt b/idea/testData/quickfix/canBePrimaryConstructorProperty/vararg.kt new file mode 100644 index 00000000000..b16ffc9f8d3 --- /dev/null +++ b/idea/testData/quickfix/canBePrimaryConstructorProperty/vararg.kt @@ -0,0 +1,4 @@ +// "Move to constructor" "true" +class A(vararg strings: String) { + val strings = strings +} \ No newline at end of file diff --git a/idea/testData/quickfix/canBePrimaryConstructorProperty/vararg.kt.after b/idea/testData/quickfix/canBePrimaryConstructorProperty/vararg.kt.after new file mode 100644 index 00000000000..9dac4474eaf --- /dev/null +++ b/idea/testData/quickfix/canBePrimaryConstructorProperty/vararg.kt.after @@ -0,0 +1,3 @@ +// "Move to constructor" "true" +class A(vararg val strings: String) { +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index f5a65b0be3c..43365666f4a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -1018,6 +1018,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/canBePrimaryConstructorProperty/simple.kt"); doTest(fileName); } + + @TestMetadata("vararg.kt") + public void testVararg() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/canBePrimaryConstructorProperty/vararg.kt"); + doTest(fileName); + } } @TestMetadata("idea/testData/quickfix/changeSignature")