From fa58da85ee1bf7e1563145ba79e84510315d491d Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Sat, 2 Jun 2018 08:48:28 +0300 Subject: [PATCH] Add indices: don't suggest if parameter is destructuring declaration So #KT-22162 Fixed --- .../kotlin/idea/intentions/AddForLoopIndicesIntention.kt | 1 + .../inapplicableDestructuringDeclaration.kt | 7 +++++++ .../kotlin/idea/intentions/IntentionTestGenerated.java | 5 +++++ 3 files changed, 13 insertions(+) create mode 100644 idea/testData/intentions/addForLoopIndices/inapplicableDestructuringDeclaration.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddForLoopIndicesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddForLoopIndicesIntention.kt index 7e1033f3245..e1533126ed8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddForLoopIndicesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddForLoopIndicesIntention.kt @@ -38,6 +38,7 @@ class AddForLoopIndicesIntention : SelfTargetingRangeIntention( override fun applicabilityRange(element: KtForExpression): TextRange? { if (element.loopParameter == null) return null + if (element.loopParameter?.destructuringDeclaration != null) return null val loopRange = element.loopRange ?: return null val bindingContext = element.analyze(BodyResolveMode.PARTIAL_WITH_CFA) diff --git a/idea/testData/intentions/addForLoopIndices/inapplicableDestructuringDeclaration.kt b/idea/testData/intentions/addForLoopIndices/inapplicableDestructuringDeclaration.kt new file mode 100644 index 00000000000..56c4788f126 --- /dev/null +++ b/idea/testData/intentions/addForLoopIndices/inapplicableDestructuringDeclaration.kt @@ -0,0 +1,7 @@ +// IS_APPLICABLE: false +// WITH_RUNTIME +fun test() { + val list = listOf(Pair("foo", "bar")) + for ((x, y) in list) { + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index a0b1ced6d5b..284a4334a46 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -801,6 +801,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/addForLoopIndices/explicitParamType.kt"); } + @TestMetadata("inapplicableDestructuringDeclaration.kt") + public void testInapplicableDestructuringDeclaration() throws Exception { + runTest("idea/testData/intentions/addForLoopIndices/inapplicableDestructuringDeclaration.kt"); + } + @TestMetadata("inapplicableExistingIndices.kt") public void testInapplicableExistingIndices() throws Exception { runTest("idea/testData/intentions/addForLoopIndices/inapplicableExistingIndices.kt");