"Replace if with when": do not add empty else block #KT-18681 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
3e207fd6b2
commit
0ae2054af4
+1
-1
@@ -63,7 +63,7 @@ class IfToWhenIntention : SelfTargetingRangeIntention<KtIfExpression>(KtIfExpres
|
||||
builder.append(nextSibling.text)
|
||||
nextSibling = nextSibling.nextSibling ?: break
|
||||
}
|
||||
KtPsiFactory(ifExpression).createBlock(builder.toString())
|
||||
KtPsiFactory(ifExpression).createBlock(builder.toString()).takeIf { it.statements.isNotEmpty() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fun test(a: Any, b: Boolean): Int {
|
||||
when (a) {
|
||||
is Int -> {
|
||||
<caret>if (b) return 1
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun test(a: Any, b: Boolean): Int {
|
||||
when (a) {
|
||||
is Int -> {
|
||||
when {
|
||||
b -> return 1
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@@ -2514,6 +2514,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
runTest("idea/testData/intentions/branched/ifWhen/ifToWhen/ifElseSwallowTail.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ifThenReturn.kt")
|
||||
public void testIfThenReturn() throws Exception {
|
||||
runTest("idea/testData/intentions/branched/ifWhen/ifToWhen/ifThenReturn.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ifWithEqualityTests.kt")
|
||||
public void testIfWithEqualityTests() throws Exception {
|
||||
runTest("idea/testData/intentions/branched/ifWhen/ifToWhen/ifWithEqualityTests.kt");
|
||||
|
||||
Reference in New Issue
Block a user