Optimize "replace toString() with string template"

Related to KT-13782
This commit is contained in:
Mikhail Glukhikh
2018-06-20 17:15:41 +03:00
parent 7a1cf5704e
commit e1d223937b
@@ -39,6 +39,9 @@ class ReplaceToStringWithStringTemplateInspection : AbstractApplicabilityBasedIn
override val defaultFixText = "Replace 'toString' with string template" override val defaultFixText = "Replace 'toString' with string template"
private fun KtDotQualifiedExpression.isToString(): Boolean { private fun KtDotQualifiedExpression.isToString(): Boolean {
val callExpression = selectorExpression as? KtCallExpression ?: return false
val referenceExpression = callExpression.calleeExpression as? KtNameReferenceExpression ?: return false
if (referenceExpression.getReferencedName() != "toString") return false
val resolvedCall = toResolvedCall(BodyResolveMode.PARTIAL) ?: return false val resolvedCall = toResolvedCall(BodyResolveMode.PARTIAL) ?: return false
val callableDescriptor = resolvedCall.resultingDescriptor as? CallableMemberDescriptor ?: return false val callableDescriptor = resolvedCall.resultingDescriptor as? CallableMemberDescriptor ?: return false
return callableDescriptor.getDeepestSuperDeclarations().any { it.fqNameUnsafe.asString() == "kotlin.Any.toString" } return callableDescriptor.getDeepestSuperDeclarations().any { it.fqNameUnsafe.asString() == "kotlin.Any.toString" }