Handle break / continue / throw in lift return / assignment intentions
So #KT-14900 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
523cbc6723
commit
8f33bd0768
+3
@@ -75,6 +75,8 @@ object BranchedFoldingUtils {
|
|||||||
is KtCallExpression -> {
|
is KtCallExpression -> {
|
||||||
e.analyze().getType(e)?.isNothing() ?: false
|
e.analyze().getType(e)?.isNothing() ?: false
|
||||||
}
|
}
|
||||||
|
is KtBreakExpression, is KtContinueExpression,
|
||||||
|
is KtThrowExpression, is KtReturnExpression -> true
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,6 +106,7 @@ object BranchedFoldingUtils {
|
|||||||
is KtCallExpression -> {
|
is KtCallExpression -> {
|
||||||
expression.analyze().getType(expression)?.isNothing() ?: false
|
expression.analyze().getType(expression)?.isNothing() ?: false
|
||||||
}
|
}
|
||||||
|
is KtBreakExpression, is KtContinueExpression, is KtThrowExpression -> true
|
||||||
else -> false
|
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
|
||||||
|
}
|
||||||
+13
@@ -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);
|
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")
|
@TestMetadata("simpleWhen.kt")
|
||||||
public void testSimpleWhen() throws Exception {
|
public void testSimpleWhen() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/folding/whenToAssignment/simpleWhen.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/folding/whenToAssignment/simpleWhen.kt");
|
||||||
@@ -1203,6 +1209,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("simpleWhen.kt")
|
||||||
public void testSimpleWhen() throws Exception {
|
public void testSimpleWhen() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/folding/whenToReturn/simpleWhen.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/folding/whenToReturn/simpleWhen.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user