Extract Function: Utilize pseudo-value usage for return type inference

This commit is contained in:
Alexey Sedunov
2014-05-30 13:06:06 +04:00
parent 164338d6f5
commit 1a7e6eab61
35 changed files with 494 additions and 145 deletions
@@ -0,0 +1,17 @@
fun bar(a: Int): Int {
println(a)
return a + 10
}
// SIBLING:
fun foo(a: Int) {
val b: Int = 1
<selection>if(a > 0) {
bar(a)
}
else {
b
}
</selection>
}
@@ -0,0 +1,20 @@
fun bar(a: Int): Int {
println(a)
return a + 10
}
// SIBLING:
fun foo(a: Int) {
val b: Int = 1
unit(a, b)
}
fun unit(a: Int, b: Int) {
if (a > 0) {
bar(a)
} else {
b
}
}
@@ -0,0 +1,11 @@
fun bar(a: Int): Int {
println(a)
return a + 10
}
// SIBLING:
fun foo(a: Int) {
val b: Int = 1
<selection>if(a > 0) bar(a) else b</selection>
}
@@ -0,0 +1,15 @@
fun bar(a: Int): Int {
println(a)
return a + 10
}
// SIBLING:
fun foo(a: Int) {
val b: Int = 1
unit(a, b)
}
fun unit(a: Int, b: Int) {
if (a > 0) bar(a) else b
}
@@ -0,0 +1,19 @@
fun bar(a: Int): Int {
println(a)
return a + 10
}
// SIBLING:
fun foo(a: Int) {
val b: Int = 1
<selection>when {
a > 0 -> {
bar(a)
}
else -> {
b
}
}
</selection>
}
@@ -0,0 +1,23 @@
fun bar(a: Int): Int {
println(a)
return a + 10
}
// SIBLING:
fun foo(a: Int) {
val b: Int = 1
unit(a, b)
}
fun unit(a: Int, b: Int) {
when {
a > 0 -> {
bar(a)
}
else -> {
b
}
}
}
@@ -0,0 +1,15 @@
fun bar(a: Int): Int {
println(a)
return a + 10
}
// SIBLING:
fun foo(a: Int) {
val b: Int = 1
<selection>when {
a > 0 -> bar(a)
else -> b
}
</selection>
}
@@ -0,0 +1,19 @@
fun bar(a: Int): Int {
println(a)
return a + 10
}
// SIBLING:
fun foo(a: Int) {
val b: Int = 1
unit(a, b)
}
fun unit(a: Int, b: Int) {
when {
a > 0 -> bar(a)
else -> b
}
}
@@ -0,0 +1,5 @@
// SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
return if (<selection>a + b > 0</selection>) 1 else if (a - b < 0) 2 else b
}
@@ -0,0 +1,9 @@
// SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
return if (b(a, b)) 1 else if (a - b < 0) 2 else b
}
fun b(a: Int, b: Int): Boolean {
return a + b > 0
}
@@ -0,0 +1,5 @@
// SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
return if (a + b > 0) 1 else <selection>if (a - b < 0) 2 else b</selection>
}
@@ -0,0 +1,9 @@
// SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
return if (a + b > 0) 1 else i(a, b)
}
fun i(a: Int, b: Int): Int {
return if (a - b < 0) 2 else b
}
@@ -0,0 +1,5 @@
// SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
return if (a + b > 0) <selection>1</selection> else if (a - b < 0) 2 else b
}
@@ -0,0 +1,9 @@
// SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
return if (a + b > 0) i() else if (a - b < 0) 2 else b
}
fun i(): Int {
return 1
}
@@ -0,0 +1,9 @@
// SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
return when (a + b) {
0 -> <selection>b</selection>
1 -> -b
else -> a - b
}
}
@@ -0,0 +1,13 @@
// SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
return when (a + b) {
0 -> i(b)
1 -> -b
else -> a - b
}
}
fun i(b: Int): Int {
return b
}
@@ -0,0 +1,9 @@
// SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
return when (a + b) {
<selection>0</selection> -> b
1 -> -b
else -> a - b
}
}
@@ -0,0 +1,13 @@
// SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
return when (a + b) {
i() -> b
1 -> -b
else -> a - b
}
}
fun i(): Int {
return 0
}
@@ -0,0 +1,9 @@
// SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
return when (<selection>a + b</selection>) {
0 -> b
1 -> -b
else -> a - b
}
}
@@ -0,0 +1,13 @@
// SIBLING:
fun foo(a: Int): Int {
val b: Int = 1
return when (i(a, b)) {
0 -> b
1 -> -b
else -> a - b
}
}
fun i(a: Int, b: Int): Int {
return a + b
}
@@ -0,0 +1,2 @@
// SIBLING:
fun foo(a: Int, b: Int): Int = <selection>a + b</selection>
@@ -0,0 +1,6 @@
// SIBLING:
fun foo(a: Int, b: Int): Int = i(a, b)
fun i(a: Int, b: Int): Int {
return a + b
}
@@ -0,0 +1,15 @@
// SIBLING:
fun foo(a: Int): Int {
var b: Int = 1
b = i(b)
return b
}
fun i(b: Int): Int {
var b1 = b
if (n == 10) throw Exception("")
b1++
return b1
}
@@ -1 +0,0 @@
Selected code fragment has output values as well as alternative exit points