diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/BranchedFoldingUtils.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/BranchedFoldingUtils.kt index 0bf6d753f5b..583a81e8439 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/BranchedFoldingUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/BranchedFoldingUtils.kt @@ -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 } diff --git a/idea/testData/intentions/branched/folding/whenToAssignment/insideLoop.kt b/idea/testData/intentions/branched/folding/whenToAssignment/insideLoop.kt new file mode 100644 index 00000000000..c2016bf11f9 --- /dev/null +++ b/idea/testData/intentions/branched/folding/whenToAssignment/insideLoop.kt @@ -0,0 +1,13 @@ +fun foo(): Int { + var res = 0 + loop@ while (true) { + when (1) { + 1 -> res += 1 + 2 -> throw Exception() + 3 -> break@loop + 4 -> continue@loop + else -> return -1 + } + } + return res +} \ No newline at end of file diff --git a/idea/testData/intentions/branched/folding/whenToAssignment/insideLoop.kt.after b/idea/testData/intentions/branched/folding/whenToAssignment/insideLoop.kt.after new file mode 100644 index 00000000000..b4d2e79e053 --- /dev/null +++ b/idea/testData/intentions/branched/folding/whenToAssignment/insideLoop.kt.after @@ -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 +} \ No newline at end of file diff --git a/idea/testData/intentions/branched/folding/whenToReturn/insideLoop.kt b/idea/testData/intentions/branched/folding/whenToReturn/insideLoop.kt new file mode 100644 index 00000000000..687852d811f --- /dev/null +++ b/idea/testData/intentions/branched/folding/whenToReturn/insideLoop.kt @@ -0,0 +1,12 @@ +fun foo(): Int { + loop@ while (true) { + when (1) { + 1 -> return 1 + 2 -> throw Exception() + 3 -> break@loop + 4 -> continue@loop + else -> return -1 + } + } + return 0 +} \ No newline at end of file diff --git a/idea/testData/intentions/branched/folding/whenToReturn/insideLoop.kt.after b/idea/testData/intentions/branched/folding/whenToReturn/insideLoop.kt.after new file mode 100644 index 00000000000..8f5252f48db --- /dev/null +++ b/idea/testData/intentions/branched/folding/whenToReturn/insideLoop.kt.after @@ -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 +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 65858dd9ec0..805fc13ad5b 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -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");