Simplify for intention: now is not active if map / data class properties aren't used in a loop #KT-11716 Fixed

This commit is contained in:
Mikhail Glukhikh
2016-05-17 14:49:58 +03:00
parent 3930184f1f
commit d366da5cd6
3 changed files with 15 additions and 1 deletions

View File

@@ -57,7 +57,8 @@ class SimplifyForIntention : SelfTargetingRangeIntention<KtForExpression>(
override fun applicabilityRange(element: KtForExpression): TextRange? {
if (element.destructuringParameter != null) return null
if (collectPropertiesToRemove(element) != null) {
val propertiesToRemove = collectPropertiesToRemove(element)
if (propertiesToRemove != null && propertiesToRemove.first.isNotEmpty()) {
return element.loopParameter!!.textRange
}
return null

View File

@@ -0,0 +1,7 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
data class XY(val x: String, val y: String)
fun test(xys: Array<XY>) {
for (<caret>xy in xys) {}
}

View File

@@ -6537,6 +6537,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("DataClassUnused.kt")
public void testDataClassUnused() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/iterationOverMap/DataClassUnused.kt");
doTest(fileName);
}
@TestMetadata("EntriesCallIsMissing.kt")
public void testEntriesCallIsMissing() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/iterationOverMap/EntriesCallIsMissing.kt");