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 148faa626c6..ac3290ce80e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt @@ -69,7 +69,9 @@ fun KtExpression.unwrapBlockOrParenthesis(): KtExpression { val innerExpression = KtPsiUtil.safeDeparenthesize(this, true) if (innerExpression is KtBlockExpression) { val statement = innerExpression.statements.singleOrNull() ?: return this - return KtPsiUtil.safeDeparenthesize(statement, true) + val deparenthesized = KtPsiUtil.safeDeparenthesize(statement, true) + if (deparenthesized is KtLambdaExpression) return this + return deparenthesized } return innerExpression } diff --git a/idea/testData/intentions/branched/ifWhen/ifToWhen/lambdaExpression.kt b/idea/testData/intentions/branched/ifWhen/ifToWhen/lambdaExpression.kt new file mode 100644 index 00000000000..eeed6960985 --- /dev/null +++ b/idea/testData/intentions/branched/ifWhen/ifToWhen/lambdaExpression.kt @@ -0,0 +1,9 @@ +fun test(x: Int) { + val f: Function = if (x == 0) { + { 0 } + } else if (x == 1) { + { 1 } + } else { + { 2 } + } +} \ No newline at end of file diff --git a/idea/testData/intentions/branched/ifWhen/ifToWhen/lambdaExpression.kt.after b/idea/testData/intentions/branched/ifWhen/ifToWhen/lambdaExpression.kt.after new file mode 100644 index 00000000000..2b5d55bf770 --- /dev/null +++ b/idea/testData/intentions/branched/ifWhen/ifToWhen/lambdaExpression.kt.after @@ -0,0 +1,13 @@ +fun test(x: Int) { + val f: Function = when (x) { + 0 -> { + { 0 } + } + 1 -> { + { 1 } + } + else -> { + { 2 } + } + } +} \ No newline at end of file diff --git a/idea/testData/intentions/branched/ifWhen/ifToWhen/lambdaExpression2.kt b/idea/testData/intentions/branched/ifWhen/ifToWhen/lambdaExpression2.kt new file mode 100644 index 00000000000..507f2f59ff9 --- /dev/null +++ b/idea/testData/intentions/branched/ifWhen/ifToWhen/lambdaExpression2.kt @@ -0,0 +1,9 @@ +fun test(x: Int) { + val f: Function = if (x == 0) { + ({ 0 }) + } else if (x == 1) { + (({ 1 })) + } else { + ((({ 2 }))) + } +} \ No newline at end of file diff --git a/idea/testData/intentions/branched/ifWhen/ifToWhen/lambdaExpression2.kt.after b/idea/testData/intentions/branched/ifWhen/ifToWhen/lambdaExpression2.kt.after new file mode 100644 index 00000000000..0fd12b68b97 --- /dev/null +++ b/idea/testData/intentions/branched/ifWhen/ifToWhen/lambdaExpression2.kt.after @@ -0,0 +1,13 @@ +fun test(x: Int) { + val f: Function = when (x) { + 0 -> { + ({ 0 }) + } + 1 -> { + (({ 1 })) + } + else -> { + ((({ 2 }))) + } + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 64c02d9b4cf..209bc416121 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -2564,6 +2564,16 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/branched/ifWhen/ifToWhen/ifWithoutElse.kt"); } + @TestMetadata("lambdaExpression.kt") + public void testLambdaExpression() throws Exception { + runTest("idea/testData/intentions/branched/ifWhen/ifToWhen/lambdaExpression.kt"); + } + + @TestMetadata("lambdaExpression2.kt") + public void testLambdaExpression2() throws Exception { + runTest("idea/testData/intentions/branched/ifWhen/ifToWhen/lambdaExpression2.kt"); + } + @TestMetadata("multipleIfFake.kt") public void testMultipleIfFake() throws Exception { runTest("idea/testData/intentions/branched/ifWhen/ifToWhen/multipleIfFake.kt");