"Add missing component" intention: fix it works correctly if entries is empty

#KT-36094 Fixed
This commit is contained in:
Toshiaki Kameyama
2020-01-23 22:53:26 +09:00
committed by Ilya Kirillov
parent 0a215cafa7
commit 34cfe7dfdb
4 changed files with 18 additions and 2 deletions
@@ -40,8 +40,9 @@ class AddMissingDestructuringIntention :
filter = NewDeclarationNameValidator(element.parent.parent, null, NewDeclarationNameValidator.Target.VARIABLES)
)
val newEntries = entries.joinToString(postfix = ", ") { it.text } +
primaryParameters.asSequence().drop(entries.size).joinToString {
val entriesSize = entries.size
val newEntries = entries.joinToString(postfix = if (entriesSize == 0) "" else ", ") { it.text } +
primaryParameters.asSequence().drop(entriesSize).joinToString {
KotlinNameSuggester.suggestNameByName(it.name.asString(), nameValidator)
}
val initializer = element.initializer ?: return
@@ -0,0 +1,5 @@
data class Foo(val a: String, val b: String, val c: String)
fun bar(f: Foo) {
val (<caret>) = f
}
@@ -0,0 +1,5 @@
data class Foo(val a: String, val b: String, val c: String)
fun bar(f: Foo) {
val (a, b, c) = f
}
@@ -1142,6 +1142,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/intentions/addMissingDestructuring"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true);
}
@TestMetadata("empty.kt")
public void testEmpty() throws Exception {
runTest("idea/testData/intentions/addMissingDestructuring/empty.kt");
}
@TestMetadata("notAvailable.kt")
public void testNotAvailable() throws Exception {
runTest("idea/testData/intentions/addMissingDestructuring/notAvailable.kt");