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 5b2b068c404..135e26ace7d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt @@ -277,10 +277,10 @@ data class IfThenToSelectData( internal fun KtIfExpression.buildSelectTransformationData(): IfThenToSelectData? { val context = analyze() - val condition = condition as? KtOperationExpression ?: return null + val condition = condition?.unwrapBlockOrParenthesis() as? KtOperationExpression ?: return null val thenClause = then?.unwrapBlockOrParenthesis() val elseClause = `else`?.unwrapBlockOrParenthesis() - val receiverExpression = condition.checkedExpression() ?: return null + val receiverExpression = condition.checkedExpression()?.unwrapBlockOrParenthesis() ?: return null val (baseClause, negatedClause) = when (condition) { is KtBinaryExpression -> when (condition.operationToken) { diff --git a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/conditionInParentheses.kt b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/conditionInParentheses.kt new file mode 100644 index 00000000000..55b36d7a849 --- /dev/null +++ b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/conditionInParentheses.kt @@ -0,0 +1,9 @@ +class Some { + fun bar() {} +} + +fun Some?.foo() { + if (((this) != null)) { + bar() + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/conditionInParentheses.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/conditionInParentheses.kt.after new file mode 100644 index 00000000000..9a72737fa00 --- /dev/null +++ b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/conditionInParentheses.kt.after @@ -0,0 +1,7 @@ +class Some { + fun bar() {} +} + +fun Some?.foo() { + this?.bar() +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 0f3251f7517..782e2a5aafd 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -106,6 +106,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { runTest("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/conditionComparesNullWithNull.kt"); } + @TestMetadata("conditionInParentheses.kt") + public void testConditionInParentheses() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/conditionInParentheses.kt"); + } + @TestMetadata("conditionInvalidBinaryExp.kt") public void testConditionInvalidBinaryExp() throws Exception { runTest("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/conditionInvalidBinaryExp.kt");