diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/branchedTransformations/IfThenToSafeAccessInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/branchedTransformations/IfThenToSafeAccessInspection.kt index bbd0bcd172a..5eba8c5106d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/branchedTransformations/IfThenToSafeAccessInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/branchedTransformations/IfThenToSafeAccessInspection.kt @@ -86,15 +86,11 @@ class IfThenToSafeAccessInspection : AbstractApplicabilityBasedInspection false negatedClause == null && baseClause.isUsedAsExpression(context) -> false negatedClause != null && !negatedClause.isNullExpression() -> false - else -> baseClause.evaluatesTo(receiverExpression) || baseClause.hasFirstReceiverOf(receiverExpression) || - receiverExpression is KtThisExpression && getImplicitReceiver()?.let { it.type == receiverExpression.getType(context) } == true || - replaceableCallExpression() - } - - private fun IfThenToSelectData.replaceableCallExpression(): Boolean { - val callExpression = baseClause as? KtCallExpression ?: return false - val arguments = callExpression.valueArguments.map { it.getArgumentExpression() } - return arguments.any { it?.evaluatesTo(receiverExpression) == true } && arguments.all { it is KtNameReferenceExpression } + baseClause.evaluatesTo(receiverExpression) -> true + baseClause.hasFirstReceiverOf(receiverExpression) -> true + baseClause.anyArgumentEvaluatesTo(receiverExpression) -> true + receiverExpression is KtThisExpression -> getImplicitReceiver()?.let { it.type == receiverExpression.getType(context) } == true + else -> false } private fun KtSafeQualifiedExpression.renameLetParameter(editor: Editor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt index 5c9aa19a2e3..ea0f6e6411b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt @@ -106,6 +106,12 @@ fun KtThrowExpression.throwsNullPointerExceptionWithNoArguments(): Boolean { fun KtExpression.evaluatesTo(other: KtExpression): Boolean = this.unwrapBlockOrParenthesis().text == other.text +fun KtExpression.anyArgumentEvaluatesTo(argument: KtExpression): Boolean { + val callExpression = this as? KtCallExpression ?: return false + val arguments = callExpression.valueArguments.map { it.getArgumentExpression() } + return arguments.any { it?.evaluatesTo(argument) == true } && arguments.all { it is KtNameReferenceExpression } +} + fun KtExpression.convertToIfNotNullExpression( conditionLhs: KtExpression, thenClause: KtExpression,