Handle break / continue / throw in lift return / assignment intentions

So #KT-14900 Fixed
This commit is contained in:
Mikhail Glukhikh
2017-06-27 12:23:37 +03:00
committed by Mikhail Glukhikh
parent 523cbc6723
commit 8f33bd0768
6 changed files with 65 additions and 0 deletions
@@ -75,6 +75,8 @@ object BranchedFoldingUtils {
is KtCallExpression -> {
e.analyze().getType(e)?.isNothing() ?: false
}
is KtBreakExpression, is KtContinueExpression,
is KtThrowExpression, is KtReturnExpression -> true
else -> false
}
}
@@ -104,6 +106,7 @@ object BranchedFoldingUtils {
is KtCallExpression -> {
expression.analyze().getType(expression)?.isNothing() ?: false
}
is KtBreakExpression, is KtContinueExpression, is KtThrowExpression -> true
else -> false
}
@@ -0,0 +1,13 @@
fun foo(): Int {
var res = 0
loop@ while (true) {
<caret>when (1) {
1 -> res += 1
2 -> throw Exception()
3 -> break@loop
4 -> continue@loop
else -> return -1
}
}
return res
}
@@ -0,0 +1,13 @@
fun foo(): Int {
var res = 0
loop@ while (true) {
res += when (1) {
1 -> 1
2 -> throw Exception()
3 -> break@loop
4 -> continue@loop
else -> return -1
}
}
return res
}
@@ -0,0 +1,12 @@
fun foo(): Int {
loop@ while (true) {
<caret>when (1) {
1 -> return 1
2 -> throw Exception()
3 -> break@loop
4 -> continue@loop
else -> return -1
}
}
return 0
}
@@ -0,0 +1,12 @@
fun foo(): Int {
loop@ while (true) {
return when (1) {
1 -> 1
2 -> throw Exception()
3 -> break@loop
4 -> continue@loop
else -> -1
}
}
return 0
}
@@ -1152,6 +1152,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("insideLoop.kt")
public void testInsideLoop() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/folding/whenToAssignment/insideLoop.kt");
doTest(fileName);
}
@TestMetadata("simpleWhen.kt")
public void testSimpleWhen() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/folding/whenToAssignment/simpleWhen.kt");
@@ -1203,6 +1209,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("insideLoop.kt")
public void testInsideLoop() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/folding/whenToReturn/insideLoop.kt");
doTest(fileName);
}
@TestMetadata("simpleWhen.kt")
public void testSimpleWhen() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/folding/whenToReturn/simpleWhen.kt");