Skip to content

Commit 8d6d228

Browse files
ndyole
authored andcommitted
Move property to constructor preserves vararg keyword (JetBrains#1095)
#KT-18035 Fixed
1 parent 965b419 commit 8d6d228

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

idea/src/org/jetbrains/kotlin/idea/intentions/MovePropertyToConstructorIntention.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor
3232
import org.jetbrains.kotlin.idea.util.CommentSaver
3333
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
3434
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
35+
import org.jetbrains.kotlin.lexer.KtTokens.VARARG_KEYWORD
3536
import org.jetbrains.kotlin.lexer.KtTokens.LATEINIT_KEYWORD
3637
import org.jetbrains.kotlin.psi.*
3738
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
@@ -86,6 +87,7 @@ class MovePropertyToConstructorIntention :
8687
element.modifierList?.getModifiersText()?.let(this::append)
8788
propertyAnnotationsText?.takeIf(String::isNotBlank)?.let { appendWithSpaceBefore(it) }
8889
parameterAnnotationsText?.let { appendWithSpaceBefore(it) }
90+
if (constructorParameter.isVarArg) appendWithSpaceBefore(VARARG_KEYWORD.value)
8991
appendWithSpaceBefore(element.valOrVarKeyword.text)
9092
element.name?.let { appendWithSpaceBefore(it) }
9193
constructorParameter.typeReference?.text?.let { append(": $it") }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// "Move to constructor" "true"
2+
class A(vararg strings: String) {
3+
val <caret>strings = strings
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// "Move to constructor" "true"
2+
class A(vararg val strings: String) {
3+
}

idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,12 @@ public void testSimple() throws Exception {
10181018
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/canBePrimaryConstructorProperty/simple.kt");
10191019
doTest(fileName);
10201020
}
1021+
1022+
@TestMetadata("vararg.kt")
1023+
public void testVararg() throws Exception {
1024+
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/canBePrimaryConstructorProperty/vararg.kt");
1025+
doTest(fileName);
1026+
}
10211027
}
10221028

10231029
@TestMetadata("idea/testData/quickfix/changeSignature")

0 commit comments

Comments
 (0)