Move property to constructor preserves vararg keyword (#1095)

#KT-18035 Fixed
This commit is contained in:
nd
2017-05-24 14:58:30 +02:00
committed by Dmitry Jemerov
parent 965b4199f4
commit 8d6d228bb8
4 changed files with 15 additions and 0 deletions
@@ -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") }
@@ -0,0 +1,4 @@
// "Move to constructor" "true"
class A(vararg strings: String) {
val <caret>strings = strings
}
@@ -0,0 +1,3 @@
// "Move to constructor" "true"
class A(vararg val strings: String) {
}
@@ -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")