From 62f81e795cd97147c57cb624f461a25954432ae7 Mon Sep 17 00:00:00 2001 From: shiraji Date: Sat, 29 Oct 2016 00:21:13 +0900 Subject: [PATCH] Redundant calls of conversion methods: do not suggest for flexible receiver types #KT-14570 Fixed --- .../RemoveRedundantCallsOfConversionMethodsIntention.kt | 8 +++++++- .../platformTypes.kt | 5 +++++ .../kotlin/idea/intentions/IntentionTestGenerated.java | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 idea/testData/intentions/removeRedundantCallsOfConversionMethods/platformTypes.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveRedundantCallsOfConversionMethodsIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveRedundantCallsOfConversionMethodsIntention.kt index 70637be91bb..89108df2caa 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveRedundantCallsOfConversionMethodsIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveRedundantCallsOfConversionMethodsIntention.kt @@ -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(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 } } diff --git a/idea/testData/intentions/removeRedundantCallsOfConversionMethods/platformTypes.kt b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/platformTypes.kt new file mode 100644 index 00000000000..260725d4960 --- /dev/null +++ b/idea/testData/intentions/removeRedundantCallsOfConversionMethods/platformTypes.kt @@ -0,0 +1,5 @@ +// WITH_RUNTIME +// IS_APPLICABLE: false +import java.util.Collections + +val foo = Collections.unmodifiableList(listOf(1)).toMutableList() \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index f7cf5d16a58..1684175a2e8 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -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");