Extract Function: Merge jumps with default exits if all exit points are equivalent
#KT-6598 Fixed
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_DESCRIPTOR: value-parameter val a: kotlin.Int defined in foo
|
||||
// PARAM_DESCRIPTOR: val b: kotlin.Int defined in foo
|
||||
// SIBLING:
|
||||
fun foo(a: Int) {
|
||||
val b: Int = 1
|
||||
for (n in 1..b) {
|
||||
<selection>if (a > 0) throw Exception("")
|
||||
if (a + b > 0) break
|
||||
println(a - b)
|
||||
return</selection>
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_DESCRIPTOR: value-parameter val a: kotlin.Int defined in foo
|
||||
// PARAM_DESCRIPTOR: val b: kotlin.Int defined in foo
|
||||
// SIBLING:
|
||||
fun foo(a: Int) {
|
||||
val b: Int = 1
|
||||
for (n in 1..b) {
|
||||
__dummyTestFun__(a, b)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
private fun __dummyTestFun__(a: Int, b: Int) {
|
||||
if (a > 0) throw Exception("")
|
||||
if (a + b > 0) return
|
||||
println(a - b)
|
||||
return
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_DESCRIPTOR: value-parameter val a: kotlin.Int defined in foo
|
||||
// PARAM_DESCRIPTOR: val b: kotlin.Int defined in foo
|
||||
// SIBLING:
|
||||
fun foo(a: Int) {
|
||||
val b: Int = 1
|
||||
@loop1 for (p in 1..b) {
|
||||
@loop2 for (n in 1..b) {
|
||||
<selection>if (a > 0) throw Exception("")
|
||||
if (a + b > 0) break@loop2
|
||||
if (a - b > 0) continue@loop1</selection>
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_DESCRIPTOR: value-parameter val a: kotlin.Int defined in foo
|
||||
// PARAM_DESCRIPTOR: val b: kotlin.Int defined in foo
|
||||
// SIBLING:
|
||||
fun foo(a: Int) {
|
||||
val b: Int = 1
|
||||
@loop1 for (p in 1..b) {
|
||||
@loop2 for (n in 1..b) {
|
||||
if (b(a, b)) break@loop2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun b(a: Int, b: Int): Boolean {
|
||||
if (a > 0) throw Exception("")
|
||||
if (a + b > 0) return true
|
||||
if (a - b > 0) return true
|
||||
return false
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// SIBLING:
|
||||
fun foo(a: Int) {
|
||||
val b: Int = 1
|
||||
for (n in 1..b) {
|
||||
<selection>if (a > 0) throw Exception("")
|
||||
if (a + b > 0) continue
|
||||
println(a - b)
|
||||
return</selection>
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
Selected code fragment has multiple exit points
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_DESCRIPTOR: value-parameter val a: kotlin.Int defined in foo
|
||||
// PARAM_DESCRIPTOR: val b: kotlin.Int defined in foo
|
||||
// SIBLING:
|
||||
fun foo(a: Int) {
|
||||
val b: Int = 1
|
||||
for (n in 1..b) {
|
||||
<selection>if (a > 0) throw Exception("")
|
||||
if (a + b > 0) break
|
||||
println(a - b)</selection>
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_DESCRIPTOR: value-parameter val a: kotlin.Int defined in foo
|
||||
// PARAM_DESCRIPTOR: val b: kotlin.Int defined in foo
|
||||
// SIBLING:
|
||||
fun foo(a: Int) {
|
||||
val b: Int = 1
|
||||
for (n in 1..b) {
|
||||
if (b(a, b)) break
|
||||
}
|
||||
}
|
||||
|
||||
private fun b(a: Int, b: Int): Boolean {
|
||||
if (a > 0) throw Exception("")
|
||||
if (a + b > 0) return true
|
||||
println(a - b)
|
||||
return false
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_DESCRIPTOR: value-parameter val a: kotlin.Int defined in foo
|
||||
// PARAM_DESCRIPTOR: val b: kotlin.Int defined in foo
|
||||
// SIBLING:
|
||||
fun foo(a: Int) {
|
||||
val b: Int = 1
|
||||
for (n in 1..b) {
|
||||
<selection>if (a > 0) throw Exception("")
|
||||
if (a + b > 0) continue
|
||||
println(a - b)</selection>
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_DESCRIPTOR: value-parameter val a: kotlin.Int defined in foo
|
||||
// PARAM_DESCRIPTOR: val b: kotlin.Int defined in foo
|
||||
// SIBLING:
|
||||
fun foo(a: Int) {
|
||||
val b: Int = 1
|
||||
for (n in 1..b) {
|
||||
__dummyTestFun__(a, b)
|
||||
}
|
||||
}
|
||||
|
||||
private fun __dummyTestFun__(a: Int, b: Int) {
|
||||
if (a > 0) throw Exception("")
|
||||
if (a + b > 0) return
|
||||
println(a - b)
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_DESCRIPTOR: value-parameter val a: kotlin.Int defined in foo
|
||||
// PARAM_DESCRIPTOR: val b: kotlin.Int defined in foo
|
||||
// SIBLING:
|
||||
fun foo(a: Int) {
|
||||
val b: Int = 1
|
||||
|
||||
<selection>if (a > 0) throw Exception("")
|
||||
if (b + a > 0) return
|
||||
println(a - b)</selection>
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_TYPES: kotlin.Int
|
||||
// PARAM_DESCRIPTOR: value-parameter val a: kotlin.Int defined in foo
|
||||
// PARAM_DESCRIPTOR: val b: kotlin.Int defined in foo
|
||||
// SIBLING:
|
||||
fun foo(a: Int) {
|
||||
val b: Int = 1
|
||||
|
||||
__dummyTestFun__(a, b)
|
||||
}
|
||||
|
||||
private fun __dummyTestFun__(a: Int, b: Int) {
|
||||
if (a > 0) throw Exception("")
|
||||
if (b + a > 0) return
|
||||
println(a - b)
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// WITH_RUNTIME
|
||||
// PARAM_TYPES: kotlin.Int, Comparable<Int>
|
||||
// PARAM_DESCRIPTOR: value-parameter val i: kotlin.Int defined in example
|
||||
fun example(i: Int) {
|
||||
when (i) {
|
||||
1 -> {
|
||||
<selection>if (i > 5) {
|
||||
println("true")
|
||||
}
|
||||
else {
|
||||
println("false")
|
||||
return
|
||||
}
|
||||
println("!!")</selection>
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// WITH_RUNTIME
|
||||
// PARAM_TYPES: kotlin.Int, Comparable<Int>
|
||||
// PARAM_DESCRIPTOR: value-parameter val i: kotlin.Int defined in example
|
||||
fun example(i: Int) {
|
||||
when (i) {
|
||||
1 -> {
|
||||
__dummyTestFun__(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun __dummyTestFun__(i: Int) {
|
||||
if (i > 5) {
|
||||
println("true")
|
||||
} else {
|
||||
println("false")
|
||||
return
|
||||
}
|
||||
println("!!")
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// SIBLING:
|
||||
fun foo(a: Int) {
|
||||
val b: Int = 1
|
||||
@loop1 for (p in 1..b) {
|
||||
@loop2 for (n in 1..b) {
|
||||
<selection>if (a > 0) throw Exception("")
|
||||
if (a + b > 0) break@loop1
|
||||
println(a - b)
|
||||
break@loop2</selection>
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
Selected code fragment has multiple exit points
|
||||
@@ -9,5 +9,6 @@ fun foo(a: Int): Int {
|
||||
<selection>if (a > 0) throw Exception("")
|
||||
if (a + b > 0) continue
|
||||
println(a - b)</selection>
|
||||
println(a + b)
|
||||
}
|
||||
}
|
||||
+1
@@ -7,6 +7,7 @@ fun foo(a: Int): Int {
|
||||
val b: Int = 1
|
||||
for (n in 1..b) {
|
||||
if (b(a, b)) continue
|
||||
println(a + b)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -9,4 +9,5 @@ fun foo(a: Int) {
|
||||
<selection>if (a > 0) throw Exception("")
|
||||
if (b + a > 0) return
|
||||
println(a - b)</selection>
|
||||
println(a + b)
|
||||
}
|
||||
+1
@@ -7,6 +7,7 @@ fun foo(a: Int) {
|
||||
val b: Int = 1
|
||||
|
||||
if (b(a, b)) return
|
||||
println(a + b)
|
||||
}
|
||||
|
||||
private fun b(a: Int, b: Int): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user