KT-15142 Remove redundant calls of the conversion method wrongly shown for Any?.toString

#KT-15142 Fixed
This commit is contained in:
shiraji
2016-12-09 00:25:55 +09:00
committed by Mikhail Glukhikh
parent 18cb734c58
commit 44ca45123d
3 changed files with 13 additions and 4 deletions
@@ -23,10 +23,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
import org.jetbrains.kotlin.js.descriptorUtils.getJetTypeFqName
import org.jetbrains.kotlin.psi.KtConstantExpression
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtQualifiedExpression
import org.jetbrains.kotlin.psi.KtStringTemplateExpression
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
@@ -69,6 +66,7 @@ class RemoveRedundantCallsOfConversionMethodsIntention : SelfTargetingRangeInten
else -> {
getResolvedCall(analyze())?.candidateDescriptor?.returnType?.let {
if (it.isFlexible()) null
else if (it.isMarkedNullable && parent !is KtSafeQualifiedExpression) null
else it.getJetTypeFqName(false)
}
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
fun foo(s: String?) {
val t: String = s.toString()<caret>
}
@@ -11805,6 +11805,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("nullable.kt")
public void testNullable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/nullable.kt");
doTest(fileName);
}
@TestMetadata("safeString.kt")
public void testSafeString() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeRedundantCallsOfConversionMethods/safeString.kt");