KT-13884 Exception "Invalid root block PSI element" on replacing trivial when-expression to if

#KT-13884 Fixed
This commit is contained in:
Valentin Kipyatkov
2016-10-04 20:44:09 +03:00
parent 597cd04831
commit c06e2d994e
4 changed files with 29 additions and 6 deletions
@@ -33,6 +33,7 @@ class WhenToIfIntention : SelfTargetingRangeIntention<KtWhenExpression>(KtWhenEx
if (entries.isEmpty()) return null
val lastEntry = entries.last()
if (entries.any { it != lastEntry && it.isElse }) return null
if (entries.all { it.isElse }) return null // 'when' with only 'else' branch is not supported
return element.whenKeyword.textRange
}
@@ -0,0 +1,6 @@
//IS_APPLICABLE: false
fun foo() {
<caret>when {
else -> {}
}
}
@@ -1771,6 +1771,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("kt13884.kt")
public void testKt13884() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifWhen/whenToIf/kt13884.kt");
doTest(fileName);
}
@TestMetadata("whenWithDotQualifiedExpression.kt")
public void testWhenWithDotQualifiedExpression() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifWhen/whenToIf/whenWithDotQualifiedExpression.kt");