Redundant calls of conversion methods: do not suggest for flexible receiver types #KT-14570 Fixed

This commit is contained in:
shiraji
2016-10-29 00:21:13 +09:00
committed by Mikhail Glukhikh
parent f9a48857f5
commit 62f81e795c
3 changed files with 18 additions and 1 deletions
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.js.descriptorUtils.getJetTypeFqName
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
import org.jetbrains.kotlin.types.isFlexible
import java.util.*
class RemoveRedundantCallsOfConversionMethodsInspection : IntentionBasedInspection<KtQualifiedExpression>(RemoveRedundantCallsOfConversionMethodsIntention::class) {
@@ -71,7 +72,12 @@ class RemoveRedundantCallsOfConversionMethodsIntention : SelfTargetingRangeInten
return when (this) {
is KtStringTemplateExpression -> String::class.qualifiedName
is KtConstantExpression -> getType(analyze())?.getJetTypeFqName(false)
else -> getResolvedCall(analyze())?.candidateDescriptor?.returnType?.getJetTypeFqName(false)
else -> {
getResolvedCall(analyze())?.candidateDescriptor?.returnType?.let {
if (it.isFlexible()) null
else it.getJetTypeFqName(false)
}
}
} == qualifiedName
}
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
import java.util.Collections
val foo = Collections.unmodifiableList(listOf(1)).toMutableList()<caret>
@@ -11231,6 +11231,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("platformTypes.kt")
public void testPlatformTypes() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/platformTypes.kt");
doTest(fileName);
}
@TestMetadata("safeSortedMap.kt")
public void testSafeSortedMap() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeSortedMap.kt");