"Replace if with when": Do not remove block braces if block has single lambda expression #KT-26187 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
e59427edab
commit
362e6863ac
+3
-1
@@ -69,7 +69,9 @@ fun KtExpression.unwrapBlockOrParenthesis(): KtExpression {
|
|||||||
val innerExpression = KtPsiUtil.safeDeparenthesize(this, true)
|
val innerExpression = KtPsiUtil.safeDeparenthesize(this, true)
|
||||||
if (innerExpression is KtBlockExpression) {
|
if (innerExpression is KtBlockExpression) {
|
||||||
val statement = innerExpression.statements.singleOrNull() ?: return this
|
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
|
return innerExpression
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
fun test(x: Int) {
|
||||||
|
val f: Function<Int> = <caret>if (x == 0) {
|
||||||
|
{ 0 }
|
||||||
|
} else if (x == 1) {
|
||||||
|
{ 1 }
|
||||||
|
} else {
|
||||||
|
{ 2 }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
fun test(x: Int) {
|
||||||
|
val f: Function<Int> = when (x) {
|
||||||
|
0 -> {
|
||||||
|
{ 0 }
|
||||||
|
}
|
||||||
|
1 -> {
|
||||||
|
{ 1 }
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
{ 2 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
fun test(x: Int) {
|
||||||
|
val f: Function<Int> = <caret>if (x == 0) {
|
||||||
|
({ 0 })
|
||||||
|
} else if (x == 1) {
|
||||||
|
(({ 1 }))
|
||||||
|
} else {
|
||||||
|
((({ 2 })))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
fun test(x: Int) {
|
||||||
|
val f: Function<Int> = when (x) {
|
||||||
|
0 -> {
|
||||||
|
({ 0 })
|
||||||
|
}
|
||||||
|
1 -> {
|
||||||
|
(({ 1 }))
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
((({ 2 })))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2564,6 +2564,16 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
runTest("idea/testData/intentions/branched/ifWhen/ifToWhen/ifWithoutElse.kt");
|
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")
|
@TestMetadata("multipleIfFake.kt")
|
||||||
public void testMultipleIfFake() throws Exception {
|
public void testMultipleIfFake() throws Exception {
|
||||||
runTest("idea/testData/intentions/branched/ifWhen/ifToWhen/multipleIfFake.kt");
|
runTest("idea/testData/intentions/branched/ifWhen/ifToWhen/multipleIfFake.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user