Simplify for: take into account local property mutability

This commit is contained in:
Mikhail Glukhikh
2016-05-18 19:25:11 +03:00
parent d0fd3dea67
commit 9108ab1923
3 changed files with 20 additions and 0 deletions
@@ -185,6 +185,7 @@ class SimplifyForIntention : SelfTargetingRangeIntention<KtForExpression>(
}
val property = parentCall.parent as? KtProperty
if (property != null && property.isVar) return null
val resolvedCall = parentCall.getResolvedCall(context) ?: return null
val descriptor = resolvedCall.resultingDescriptor
@@ -0,0 +1,13 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
data class XY(val x: String, val y: Int)
fun test(xys: Array<XY>) {
for (<caret>xy in xys) {
val x = xy.x
var y = xy.y
println(x + y)
y--
println(y)
}
}
@@ -6603,6 +6603,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("DataClassWithLocalPropertyModified.kt")
public void testDataClassWithLocalPropertyModified() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/iterationOverMap/DataClassWithLocalPropertyModified.kt");
doTest(fileName);
}
@TestMetadata("EntriesCallIsMissing.kt")
public void testEntriesCallIsMissing() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/iterationOverMap/EntriesCallIsMissing.kt");