diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/extractFunctionUtils.kt b/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/extractFunctionUtils.kt index 231d94d883f..ce3992ecba9 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/extractFunctionUtils.kt +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/extractFunctionUtils.kt @@ -169,11 +169,10 @@ private fun List.analyzeControlFlow( val element = it.getElement() if (element is JetReturnExpression || element is JetBreakExpression - || element is JetContinueExpression - || element is JetThrowExpression) { + || element is JetContinueExpression) { jumpExits.add(it) } - else { + else if (element !is JetThrowExpression) { defaultExits.add(it) } } diff --git a/idea/testData/refactoring/extractFunction/controlFlow/throws/breakWithThrow.kt b/idea/testData/refactoring/extractFunction/controlFlow/throws/breakWithThrow.kt new file mode 100644 index 00000000000..b6049a95d41 --- /dev/null +++ b/idea/testData/refactoring/extractFunction/controlFlow/throws/breakWithThrow.kt @@ -0,0 +1,9 @@ +// NEXT_SIBLING: +fun foo(a: Int): Int { + val b: Int = 1 + for (n in 1..b) { + if (a > 0) throw Exception("") + if (a + b > 0) break + println(a - b) + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/extractFunction/controlFlow/throws/breakWithThrow.kt.after b/idea/testData/refactoring/extractFunction/controlFlow/throws/breakWithThrow.kt.after new file mode 100644 index 00000000000..44916d6cf67 --- /dev/null +++ b/idea/testData/refactoring/extractFunction/controlFlow/throws/breakWithThrow.kt.after @@ -0,0 +1,14 @@ +// NEXT_SIBLING: +fun b(a: Int, b: Int): Boolean { + if (a > 0) throw Exception("") + if (a + b > 0) return true + println(a - b) + return false +} + +fun foo(a: Int): Int { + val b: Int = 1 + for (n in 1..b) { + if (b(a, b)) break + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/extractFunction/controlFlow/throws/continueWithThrow.kt b/idea/testData/refactoring/extractFunction/controlFlow/throws/continueWithThrow.kt new file mode 100644 index 00000000000..c670282c33c --- /dev/null +++ b/idea/testData/refactoring/extractFunction/controlFlow/throws/continueWithThrow.kt @@ -0,0 +1,9 @@ +// NEXT_SIBLING: +fun foo(a: Int): Int { + val b: Int = 1 + for (n in 1..b) { + if (a > 0) throw Exception("") + if (a + b > 0) continue + println(a - b) + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/extractFunction/controlFlow/throws/continueWithThrow.kt.after b/idea/testData/refactoring/extractFunction/controlFlow/throws/continueWithThrow.kt.after new file mode 100644 index 00000000000..51bb8da2f32 --- /dev/null +++ b/idea/testData/refactoring/extractFunction/controlFlow/throws/continueWithThrow.kt.after @@ -0,0 +1,14 @@ +// NEXT_SIBLING: +fun b(a: Int, b: Int): Boolean { + if (a > 0) throw Exception("") + if (a + b > 0) return true + println(a - b) + return false +} + +fun foo(a: Int): Int { + val b: Int = 1 + for (n in 1..b) { + if (b(a, b)) continue + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/extractFunction/controlFlow/unextractable/evalExpressionWithThrow.kt b/idea/testData/refactoring/extractFunction/controlFlow/throws/evalExpressionWithThrow.kt similarity index 100% rename from idea/testData/refactoring/extractFunction/controlFlow/unextractable/evalExpressionWithThrow.kt rename to idea/testData/refactoring/extractFunction/controlFlow/throws/evalExpressionWithThrow.kt diff --git a/idea/testData/refactoring/extractFunction/controlFlow/throws/evalExpressionWithThrow.kt.after b/idea/testData/refactoring/extractFunction/controlFlow/throws/evalExpressionWithThrow.kt.after new file mode 100644 index 00000000000..19de1c27d0a --- /dev/null +++ b/idea/testData/refactoring/extractFunction/controlFlow/throws/evalExpressionWithThrow.kt.after @@ -0,0 +1,11 @@ +// NEXT_SIBLING: +fun i(a: Int, b: Int): Int { + return if (a > 0) throw Exception("") else a + b +} + +fun foo(a: Int): Int { + val b: Int = 1 + + val t = i(a, b) + return t +} \ No newline at end of file diff --git a/idea/testData/refactoring/extractFunction/controlFlow/throws/nonValuedReturnWithThrow.kt b/idea/testData/refactoring/extractFunction/controlFlow/throws/nonValuedReturnWithThrow.kt new file mode 100644 index 00000000000..8fb3d2e9394 --- /dev/null +++ b/idea/testData/refactoring/extractFunction/controlFlow/throws/nonValuedReturnWithThrow.kt @@ -0,0 +1,8 @@ +// NEXT_SIBLING: +fun foo(a: Int) { + val b: Int = 1 + + if (a > 0) throw Exception("") + if (b + a > 0) return + println(a - b) +} \ No newline at end of file diff --git a/idea/testData/refactoring/extractFunction/controlFlow/throws/nonValuedReturnWithThrow.kt.after b/idea/testData/refactoring/extractFunction/controlFlow/throws/nonValuedReturnWithThrow.kt.after new file mode 100644 index 00000000000..7662624e53c --- /dev/null +++ b/idea/testData/refactoring/extractFunction/controlFlow/throws/nonValuedReturnWithThrow.kt.after @@ -0,0 +1,13 @@ +// NEXT_SIBLING: +fun b(a: Int, b: Int): Boolean { + if (a > 0) throw Exception("") + if (b + a > 0) return true + println(a - b) + return false +} + +fun foo(a: Int) { + val b: Int = 1 + + if (b(a, b)) return +} \ No newline at end of file diff --git a/idea/testData/refactoring/extractFunction/controlFlow/throws/returnWithThrow.kt b/idea/testData/refactoring/extractFunction/controlFlow/throws/returnWithThrow.kt new file mode 100644 index 00000000000..fc791ff4654 --- /dev/null +++ b/idea/testData/refactoring/extractFunction/controlFlow/throws/returnWithThrow.kt @@ -0,0 +1,7 @@ +// NEXT_SIBLING: +fun foo(a: Int): Int { + val b: Int = 1 + + if (a > 0) throw Exception("") else return a + b + return a - b +} \ No newline at end of file diff --git a/idea/testData/refactoring/extractFunction/controlFlow/throws/returnWithThrow.kt.after b/idea/testData/refactoring/extractFunction/controlFlow/throws/returnWithThrow.kt.after new file mode 100644 index 00000000000..f45038d757a --- /dev/null +++ b/idea/testData/refactoring/extractFunction/controlFlow/throws/returnWithThrow.kt.after @@ -0,0 +1,11 @@ +// NEXT_SIBLING: +fun i(a: Int, b: Int): Int { + if (a > 0) throw Exception("") else return a + b + return a - b +} + +fun foo(a: Int): Int { + val b: Int = 1 + + return i(a, b) +} \ No newline at end of file diff --git a/idea/testData/refactoring/extractFunction/controlFlow/unextractable/evalExpressionWithThrow.kt.conflicts b/idea/testData/refactoring/extractFunction/controlFlow/unextractable/evalExpressionWithThrow.kt.conflicts deleted file mode 100644 index dfc6ea81584..00000000000 --- a/idea/testData/refactoring/extractFunction/controlFlow/unextractable/evalExpressionWithThrow.kt.conflicts +++ /dev/null @@ -1 +0,0 @@ -Selected code fragment has multiple exit points \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/JetExtractionTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/JetExtractionTestGenerated.java index a5ec2c5395c..8f6dc8d095a 100644 --- a/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/JetExtractionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/JetExtractionTestGenerated.java @@ -241,7 +241,7 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest { } @TestMetadata("idea/testData/refactoring/extractFunction/controlFlow") - @InnerTestClasses({ControlFlow.ConditionalJumps.class, ControlFlow.Default.class, ControlFlow.DefiniteReturns.class, ControlFlow.EvaluateExpression.class, ControlFlow.OutputValues.class, ControlFlow.Unextractable.class}) + @InnerTestClasses({ControlFlow.ConditionalJumps.class, ControlFlow.Default.class, ControlFlow.DefiniteReturns.class, ControlFlow.EvaluateExpression.class, ControlFlow.OutputValues.class, ControlFlow.Throws.class, ControlFlow.Unextractable.class}) public static class ControlFlow extends AbstractJetExtractionTest { public void testAllFilesPresentInControlFlow() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/refactoring/extractFunction/controlFlow"), Pattern.compile("^(.+)\\.kt$"), true); @@ -412,6 +412,39 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest { } + @TestMetadata("idea/testData/refactoring/extractFunction/controlFlow/throws") + public static class Throws extends AbstractJetExtractionTest { + public void testAllFilesPresentInThrows() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/refactoring/extractFunction/controlFlow/throws"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("breakWithThrow.kt") + public void testBreakWithThrow() throws Exception { + doExtractFunctionTest("idea/testData/refactoring/extractFunction/controlFlow/throws/breakWithThrow.kt"); + } + + @TestMetadata("continueWithThrow.kt") + public void testContinueWithThrow() throws Exception { + doExtractFunctionTest("idea/testData/refactoring/extractFunction/controlFlow/throws/continueWithThrow.kt"); + } + + @TestMetadata("evalExpressionWithThrow.kt") + public void testEvalExpressionWithThrow() throws Exception { + doExtractFunctionTest("idea/testData/refactoring/extractFunction/controlFlow/throws/evalExpressionWithThrow.kt"); + } + + @TestMetadata("nonValuedReturnWithThrow.kt") + public void testNonValuedReturnWithThrow() throws Exception { + doExtractFunctionTest("idea/testData/refactoring/extractFunction/controlFlow/throws/nonValuedReturnWithThrow.kt"); + } + + @TestMetadata("returnWithThrow.kt") + public void testReturnWithThrow() throws Exception { + doExtractFunctionTest("idea/testData/refactoring/extractFunction/controlFlow/throws/returnWithThrow.kt"); + } + + } + @TestMetadata("idea/testData/refactoring/extractFunction/controlFlow/unextractable") public static class Unextractable extends AbstractJetExtractionTest { public void testAllFilesPresentInUnextractable() throws Exception { @@ -428,11 +461,6 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest { doExtractFunctionTest("idea/testData/refactoring/extractFunction/controlFlow/unextractable/evalExpressionWithReturn.kt"); } - @TestMetadata("evalExpressionWithThrow.kt") - public void testEvalExpressionWithThrow() throws Exception { - doExtractFunctionTest("idea/testData/refactoring/extractFunction/controlFlow/unextractable/evalExpressionWithThrow.kt"); - } - @TestMetadata("jumpsAndReturns.kt") public void testJumpsAndReturns() throws Exception { doExtractFunctionTest("idea/testData/refactoring/extractFunction/controlFlow/unextractable/jumpsAndReturns.kt"); @@ -478,6 +506,7 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest { suite.addTestSuite(DefiniteReturns.class); suite.addTestSuite(EvaluateExpression.class); suite.addTestSuite(OutputValues.class); + suite.addTestSuite(Throws.class); suite.addTestSuite(Unextractable.class); return suite; }