Destructure is available even without usages #KT-14435 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
feb9dd4d83
commit
d9e1e82948
@@ -74,9 +74,14 @@ class DestructureIntention : SelfTargetingRangeIntention<KtDeclaration>(
|
||||
)
|
||||
val names = ArrayList<String>()
|
||||
val underscoreSupported = element.languageVersionSettings.supportsFeature(LanguageFeature.SingleUnderscoreForParameterName)
|
||||
// For all unused we generate normal names, not underscores
|
||||
val allUnused = usagesToRemove.all { (_, usagesToReplace, variableToDrop) ->
|
||||
usagesToReplace.isEmpty() && variableToDrop == null
|
||||
}
|
||||
|
||||
usagesToRemove.forEach { (descriptor, usagesToReplace, variableToDrop, name) ->
|
||||
val suggestedName =
|
||||
if (usagesToReplace.isEmpty() && variableToDrop == null && underscoreSupported) {
|
||||
if (usagesToReplace.isEmpty() && variableToDrop == null && underscoreSupported && !allUnused) {
|
||||
"_"
|
||||
}
|
||||
else {
|
||||
@@ -233,7 +238,12 @@ class DestructureIntention : SelfTargetingRangeIntention<KtDeclaration>(
|
||||
if (!noBadUsages) return null
|
||||
|
||||
val droppedLastUnused = usagesToRemove.dropLastWhile { it.usagesToReplace.isEmpty() && it.declarationToDrop == null }
|
||||
return UsagesToRemove(droppedLastUnused, removeSelectorInLoopRange)
|
||||
return if (droppedLastUnused.isEmpty()) {
|
||||
UsagesToRemove(usagesToRemove, removeSelectorInLoopRange)
|
||||
}
|
||||
else {
|
||||
UsagesToRemove(droppedLastUnused, removeSelectorInLoopRange)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Query<PsiReference>.iterateOverMapEntryPropertiesUsages(
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
data class XY(val x: String, val y: String)
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
data class XY(val x: String, val y: String)
|
||||
fun test(xys: Array<XY>) {
|
||||
for ((x, y) in xys) {}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val map = hashMapOf(1 to 1)
|
||||
for (<caret>entry in map) {}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val map = hashMapOf(1 to 1)
|
||||
for ((key, value) in map) {}
|
||||
}
|
||||
@@ -9170,6 +9170,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoKeyOrValue.kt")
|
||||
public void testNoKeyOrValue() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/iterationOverMap/NoKeyOrValue.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("OnlyKeyUsed.kt")
|
||||
public void testOnlyKeyUsed() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/iterationOverMap/OnlyKeyUsed.kt");
|
||||
|
||||
Reference in New Issue
Block a user