Do not generate redundant .toList()

This commit is contained in:
Valentin Kipyatkov
2016-04-22 12:56:25 +03:00
parent 813060fef3
commit aa6240a0c5
8 changed files with 89 additions and 4 deletions
@@ -0,0 +1,13 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterIndexed{}'"
import java.util.*
fun foo(list: List<String>): List<String> {
val result = ArrayList<String>()
<caret>for ((index, s) in list.withIndex()) {
if (s.length > index) {
result.add(s)
}
}
return result
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterIndexed{}'"
import java.util.*
fun foo(list: List<String>): List<String> {
val <caret>result = list.filterIndexed { index, s -> s.length > index }
return result
}
@@ -0,0 +1,13 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterNotNull()'"
import java.util.ArrayList
fun foo(list: List<String?>): List<String> {
val result = ArrayList<String>()
<caret>for (s in list) {
if (s != null) {
result.add(s)
}
}
return result
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterNotNull()'"
import java.util.ArrayList
fun foo(list: List<String?>): List<String> {
val <caret>result = list.filterNotNull()
return result
}
+14
View File
@@ -0,0 +1,14 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}.map{}'"
import java.util.ArrayList
fun foo(list: List<String>): List<Int> {
val result = ArrayList<Int>()
<caret>for (s in list) {
if (s.length > 0) {
val h = s.hashCode()
result.add(h)
}
}
return result
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}.map{}'"
import java.util.ArrayList
fun foo(list: List<String>): List<Int> {
val <caret>result = list
.filter { it.length > 0 }
.map { it.hashCode() }
return result
}