Supported case when result variable initialization is not right before the loop

This commit is contained in:
Valentin Kipyatkov
2016-04-21 17:40:25 +03:00
parent 9b69c5c375
commit 27063bcd9b
11 changed files with 170 additions and 10 deletions
@@ -0,0 +1,12 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'any{}'"
fun foo(list: List<String>) {
var found = false
println("Starting the search")
<caret>for (s in list) {
if (s.length > 0) {
found = true
break
}
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'any{}'"
fun foo(list: List<String>) {
println("Starting the search")
val <caret>found = list.any { it.length > 0 }
}
@@ -0,0 +1,18 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'any{}'"
fun foo(list: List<String>, p: Int) {
var found: Boolean
if (p > 0) {
found = false
println("Starting the search")
<caret>for (s in list) {
if (s.length > 0) {
found = true
break
}
}
}
else {
found = true
}
}
@@ -0,0 +1,12 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'any{}'"
fun foo(list: List<String>, p: Int) {
var found: Boolean
if (p > 0) {
println("Starting the search")
<caret>found = list.any { it.length > 0 }
}
else {
found = true
}
}
@@ -0,0 +1,15 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterIndexed{}.map{}'"
import java.util.*
fun foo(list: List<String>): List<Int> {
val result = ArrayList<Int>()
var i = 0
<caret>for (s in list) {
if (s.length > i) {
result.add(s.length)
}
i++
}
return result
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterIndexed{}.map{}'"
import java.util.*
fun foo(list: List<String>): List<Int> {
val <caret>result = list
.filterIndexed { i, s -> s.length > i }
.map { it.length }
return result
}