diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveBracesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveBracesIntention.kt index 00e2c5dd448..e47fb3415c1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveBracesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveBracesIntention.kt @@ -51,6 +51,7 @@ class RemoveBracesIntention : SelfTargetingIntention(KtElement::class is KtWhenEntry -> { text = "Remove braces from 'when' entry" return singleStatement !is KtNamedDeclaration + && !(singleStatement is KtLambdaExpression && singleStatement.functionLiteral.arrow == null) } else -> return false } diff --git a/idea/testData/intentions/removeBraces/whenLambda2.kt b/idea/testData/intentions/removeBraces/whenLambda2.kt new file mode 100644 index 00000000000..c84180b2015 --- /dev/null +++ b/idea/testData/intentions/removeBraces/whenLambda2.kt @@ -0,0 +1,10 @@ +// IS_APPLICABLE: false +fun test(v: Boolean): (String) -> Int { + return when (v) { + true -> { { taskOne(it) } } + false -> { x -> taskTwo(x) } + } +} + +fun taskOne(s: String) = s.length +fun taskTwo(s: String) = 42 \ No newline at end of file diff --git a/idea/testData/intentions/removeBraces/whenLambda3.kt b/idea/testData/intentions/removeBraces/whenLambda3.kt new file mode 100644 index 00000000000..72507b0e5dc --- /dev/null +++ b/idea/testData/intentions/removeBraces/whenLambda3.kt @@ -0,0 +1,9 @@ +fun test(v: Boolean): (String) -> Int { + return when (v) { + true -> { { x -> taskOne(x) } } + false -> { x -> taskTwo(x) } + } +} + +fun taskOne(s: String) = s.length +fun taskTwo(s: String) = 42 \ No newline at end of file diff --git a/idea/testData/intentions/removeBraces/whenLambda3.kt.after b/idea/testData/intentions/removeBraces/whenLambda3.kt.after new file mode 100644 index 00000000000..0e39c9a2d8b --- /dev/null +++ b/idea/testData/intentions/removeBraces/whenLambda3.kt.after @@ -0,0 +1,9 @@ +fun test(v: Boolean): (String) -> Int { + return when (v) { + true -> { x -> taskOne(x) } + false -> { x -> taskTwo(x) } + } +} + +fun taskOne(s: String) = s.length +fun taskTwo(s: String) = 42 \ 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 52113f25841..8cbbec717f1 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -12825,6 +12825,16 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/removeBraces/whenLambda.kt"); } + @TestMetadata("whenLambda2.kt") + public void testWhenLambda2() throws Exception { + runTest("idea/testData/intentions/removeBraces/whenLambda2.kt"); + } + + @TestMetadata("whenLambda3.kt") + public void testWhenLambda3() throws Exception { + runTest("idea/testData/intentions/removeBraces/whenLambda3.kt"); + } + @TestMetadata("whenMultiple.kt") public void testWhenMultiple() throws Exception { runTest("idea/testData/intentions/removeBraces/whenMultiple.kt");