Fix problem with mutable map in "simplifiable call chain"

So #KT-20315 Fixed
This commit is contained in:
Mikhail Glukhikh
2017-10-10 15:23:36 +03:00
committed by Mikhail Glukhikh
parent 8e59d3e379
commit 45c9be2945
3 changed files with 15 additions and 3 deletions
@@ -59,9 +59,10 @@ class SimplifiableCallChainInspection : AbstractKotlinInspection() {
// Do not apply on maps due to lack of relevant stdlib functions
val firstReceiverType = firstResolvedCall.extensionReceiver?.type
if (firstReceiverType != null) {
val mapType = builtIns.map.defaultType
if (firstReceiverType.isSubtypeOf(mapType)) return
val firstReceiverRawType = firstReceiverType?.constructor?.declarationDescriptor?.defaultType
if (firstReceiverRawType != null) {
if (firstReceiverRawType.isSubtypeOf(builtIns.map.defaultType) ||
firstReceiverRawType.isSubtypeOf(builtIns.mutableMap.defaultType)) return
}
// Do not apply for lambdas with return inside
@@ -0,0 +1,5 @@
// PROBLEM: none
// WITH_RUNTIME
val data = mutableMapOf<String, String>()
val result = data.<caret>map { "${it.key}: ${it.value}" }.joinToString("\n")
@@ -232,6 +232,12 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
doTest(fileName);
}
@TestMetadata("joinToStringOnMap.kt")
public void testJoinToStringOnMap() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/collections/simplifiableCallChain/joinToStringOnMap.kt");
doTest(fileName);
}
@TestMetadata("joinToStringViaBuilder.kt")
public void testJoinToStringViaBuilder() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/collections/simplifiableCallChain/joinToStringViaBuilder.kt");