Revert ""Use destructuring declaration": fix it works correctly if variable name is shadowed"
This reverts commit d61158a1
This commit is contained in:
@@ -59,13 +59,9 @@ class DestructureIntention : SelfTargetingRangeIntention<KtDeclaration>(
|
|||||||
override fun applyTo(element: KtDeclaration, editor: Editor?) {
|
override fun applyTo(element: KtDeclaration, editor: Editor?) {
|
||||||
val (usagesToRemove, removeSelectorInLoopRange) = collectUsagesToRemove(element) ?: return
|
val (usagesToRemove, removeSelectorInLoopRange) = collectUsagesToRemove(element) ?: return
|
||||||
val factory = KtPsiFactory(element)
|
val factory = KtPsiFactory(element)
|
||||||
val parent = element.parent
|
|
||||||
val (container, anchor) = if (parent is KtParameterList) parent.parent to null else parent to element
|
|
||||||
val validator = NewDeclarationNameValidator(
|
val validator = NewDeclarationNameValidator(
|
||||||
container = container, anchor = anchor, target = NewDeclarationNameValidator.Target.VARIABLES,
|
container = element.parent, anchor = element, target = NewDeclarationNameValidator.Target.VARIABLES,
|
||||||
excludedDeclarations = usagesToRemove.map {
|
excludedDeclarations = usagesToRemove.map { listOfNotNull(it.declarationToDrop) }.flatten()
|
||||||
(it.declarationToDrop as? KtDestructuringDeclaration)?.entries ?: listOfNotNull(it.declarationToDrop)
|
|
||||||
}.flatten()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
val names = ArrayList<String>()
|
val names = ArrayList<String>()
|
||||||
@@ -80,7 +76,7 @@ class DestructureIntention : SelfTargetingRangeIntention<KtDeclaration>(
|
|||||||
if (usagesToReplace.isEmpty() && variableToDrop == null && underscoreSupported && !allUnused) {
|
if (usagesToReplace.isEmpty() && variableToDrop == null && underscoreSupported && !allUnused) {
|
||||||
"_"
|
"_"
|
||||||
} else {
|
} else {
|
||||||
KotlinNameSuggester.suggestNameByName(name ?: descriptor.name.asString(), validator)
|
name ?: KotlinNameSuggester.suggestNameByName(descriptor.name.asString(), validator)
|
||||||
}
|
}
|
||||||
|
|
||||||
runWriteAction {
|
runWriteAction {
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
data class XY(val x: Int, val y: Int)
|
data class XY(val x: Int, val y: Int)
|
||||||
fun test(xys: Array<XY>) {
|
fun test(xys: Array<XY>) {
|
||||||
xys.forEach { (x, y1) ->
|
xys.forEach { (x, y) ->
|
||||||
println(x)
|
println(x)
|
||||||
val y = y1 + x
|
val y = y + x
|
||||||
println(y)
|
println(y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
data class Event(val timestamp: Int, val otherVar: Int = 1, val otherVar2: String = "")
|
|
||||||
|
|
||||||
val listA = listOf(Event(1), Event(2), Event(3))
|
|
||||||
val listB = listOf(Event(1), Event(2), Event(3))
|
|
||||||
|
|
||||||
fun test2() {
|
|
||||||
listA.zip(listB) { (timestamp), <caret>it2 -> timestamp + it2.timestamp }
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
data class Event(val timestamp: Int, val otherVar: Int = 1, val otherVar2: String = "")
|
|
||||||
|
|
||||||
val listA = listOf(Event(1), Event(2), Event(3))
|
|
||||||
val listB = listOf(Event(1), Event(2), Event(3))
|
|
||||||
|
|
||||||
fun test2() {
|
|
||||||
listA.zip(listB) { (timestamp), (timestamp1) -> timestamp + timestamp1 }
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
data class A(var x: Int)
|
|
||||||
|
|
||||||
fun convert(f: (A) -> Unit) {}
|
|
||||||
|
|
||||||
fun test() {
|
|
||||||
convert <caret>{
|
|
||||||
val x = it.x
|
|
||||||
|
|
||||||
run {
|
|
||||||
val x = 1
|
|
||||||
val z = it.x
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
data class A(var x: Int)
|
|
||||||
|
|
||||||
fun convert(f: (A) -> Unit) {}
|
|
||||||
|
|
||||||
fun test() {
|
|
||||||
convert { (x1) ->
|
|
||||||
|
|
||||||
run {
|
|
||||||
val x = 1
|
|
||||||
val z = x1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
data class A(var x: Int)
|
|
||||||
|
|
||||||
fun convert(f: (A) -> Unit) {}
|
|
||||||
|
|
||||||
fun test() {
|
|
||||||
convert { <caret>a ->
|
|
||||||
val x = a.x
|
|
||||||
|
|
||||||
run {
|
|
||||||
val x = 1
|
|
||||||
val z = a.x
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
data class A(var x: Int)
|
|
||||||
|
|
||||||
fun convert(f: (A) -> Unit) {}
|
|
||||||
|
|
||||||
fun test() {
|
|
||||||
convert { (x1) ->
|
|
||||||
|
|
||||||
run {
|
|
||||||
val x = 1
|
|
||||||
val z = x1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
fun main() {
|
|
||||||
data class A(var x: Int)
|
|
||||||
|
|
||||||
val <caret>a = A(0)
|
|
||||||
val x = a.x
|
|
||||||
|
|
||||||
run {
|
|
||||||
val x = 1
|
|
||||||
val z = a.x
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
fun main() {
|
|
||||||
data class A(var x: Int)
|
|
||||||
|
|
||||||
val (x1) = A(0)
|
|
||||||
|
|
||||||
run {
|
|
||||||
val x = 1
|
|
||||||
val z = x1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8757,21 +8757,6 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
runTest("idea/testData/intentions/destructuringInLambda/fold.kt");
|
runTest("idea/testData/intentions/destructuringInLambda/fold.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("hasSameNameParameter.kt")
|
|
||||||
public void testHasSameNameParameter() throws Exception {
|
|
||||||
runTest("idea/testData/intentions/destructuringInLambda/hasSameNameParameter.kt");
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("hasShadowedVariable.kt")
|
|
||||||
public void testHasShadowedVariable() throws Exception {
|
|
||||||
runTest("idea/testData/intentions/destructuringInLambda/hasShadowedVariable.kt");
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("hasShadowedVariable2.kt")
|
|
||||||
public void testHasShadowedVariable2() throws Exception {
|
|
||||||
runTest("idea/testData/intentions/destructuringInLambda/hasShadowedVariable2.kt");
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("invisible.kt")
|
@TestMetadata("invisible.kt")
|
||||||
public void testInvisible() throws Exception {
|
public void testInvisible() throws Exception {
|
||||||
runTest("idea/testData/intentions/destructuringInLambda/invisible.kt");
|
runTest("idea/testData/intentions/destructuringInLambda/invisible.kt");
|
||||||
@@ -8883,11 +8868,6 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
runTest("idea/testData/intentions/destructuringVariables/classProperty.kt");
|
runTest("idea/testData/intentions/destructuringVariables/classProperty.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("hasShadowedVariable.kt")
|
|
||||||
public void testHasShadowedVariable() throws Exception {
|
|
||||||
runTest("idea/testData/intentions/destructuringVariables/hasShadowedVariable.kt");
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("noInitializer.kt")
|
@TestMetadata("noInitializer.kt")
|
||||||
public void testNoInitializer() throws Exception {
|
public void testNoInitializer() throws Exception {
|
||||||
runTest("idea/testData/intentions/destructuringVariables/noInitializer.kt");
|
runTest("idea/testData/intentions/destructuringVariables/noInitializer.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user