Optimize "replace toString() with string template"
Related to KT-13782
This commit is contained in:
+3
@@ -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" }
|
||||||
|
|||||||
Reference in New Issue
Block a user