Simplify for: take into account loop parameter nullability
This commit is contained in:
@@ -78,7 +78,9 @@ class SimplifyForIntention : SelfTargetingRangeIntention<KtForExpression>(
|
|||||||
val context = element.analyzeFullyAndGetResult().bindingContext
|
val context = element.analyzeFullyAndGetResult().bindingContext
|
||||||
|
|
||||||
val loopParameterDescriptor = context.get(BindingContext.VALUE_PARAMETER, loopParameter) ?: return null
|
val loopParameterDescriptor = context.get(BindingContext.VALUE_PARAMETER, loopParameter) ?: return null
|
||||||
val classDescriptor = loopParameterDescriptor.type.constructor.declarationDescriptor as? ClassDescriptor ?: return null
|
val loopParameterType = loopParameterDescriptor.type
|
||||||
|
if (loopParameterType.isMarkedNullable) return null
|
||||||
|
val classDescriptor = loopParameterType.constructor.declarationDescriptor as? ClassDescriptor ?: return null
|
||||||
|
|
||||||
var otherUsages = false
|
var otherUsages = false
|
||||||
val usagesToRemove : Array<UsageData?>
|
val usagesToRemove : Array<UsageData?>
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
data class XY(val x: String, val y: String)
|
||||||
|
fun test(xys: Array<XY?>) {
|
||||||
|
for (<caret>xy in xys) {
|
||||||
|
val x = xy?.x
|
||||||
|
val y = xy?.y
|
||||||
|
println(x + y)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6555,6 +6555,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("DataClassNullable.kt")
|
||||||
|
public void testDataClassNullable() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/iterationOverMap/DataClassNullable.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("DataClassParametersOrder.kt")
|
@TestMetadata("DataClassParametersOrder.kt")
|
||||||
public void testDataClassParametersOrder() throws Exception {
|
public void testDataClassParametersOrder() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/iterationOverMap/DataClassParametersOrder.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/iterationOverMap/DataClassParametersOrder.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user