Redundant calls of conversion methods: do not suggest for flexible receiver types #KT-14570 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
f9a48857f5
commit
62f81e795c
+7
-1
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user