When to if now add braces for if branches inside #KT-12942 Fixed

(cherry picked from commit 29a7bfe)
This commit is contained in:
Mikhail Glukhikh
2016-07-11 19:09:12 +03:00
committed by Mikhail Glukhikh
parent b675b49daf
commit 3fe114fc24
4 changed files with 34 additions and 0 deletions
@@ -22,6 +22,7 @@ import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.idea.intentions.SelfTargetingRangeIntention
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.combineWhenConditions
import org.jetbrains.kotlin.idea.util.CommentSaver
import org.jetbrains.kotlin.psi.KtIfExpression
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.psi.KtWhenExpression
import org.jetbrains.kotlin.psi.buildExpression
@@ -54,7 +55,13 @@ class WhenToIfIntention : SelfTargetingRangeIntention<KtWhenExpression>(KtWhenEx
appendFixedText("if (")
appendExpression(condition)
appendFixedText(")")
if (branch is KtIfExpression) {
appendFixedText("{ ")
}
appendExpression(branch)
if (branch is KtIfExpression) {
appendFixedText(" }")
}
}
if (i != entries.lastIndex) {
appendFixedText("\n")
@@ -0,0 +1,11 @@
// KT-12942: when to if changes semantics
fun test(b: Boolean): String {
<caret>when (b) {
true ->
if (true) return "first"
false ->
if (true) return "second"
}
return "none"
}
@@ -0,0 +1,10 @@
// KT-12942: when to if changes semantics
fun test(b: Boolean): String {
if (b == true) {
if (true) return "first"
} else if (b == false) {
if (true) return "second"
}
return "none"
}
@@ -1711,6 +1711,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("whenWithIf.kt")
public void testWhenWithIf() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifWhen/whenToIf/whenWithIf.kt");
doTest(fileName);
}
@TestMetadata("whenWithMultiConditions.kt")
public void testWhenWithMultiConditions() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifWhen/whenToIf/whenWithMultiConditions.kt");