Supported indexOfFirst/indexOfLast

This commit is contained in:
Valentin Kipyatkov
2016-04-22 15:42:37 +03:00
parent 5ac2c48879
commit b65ecdd660
21 changed files with 400 additions and 292 deletions
@@ -0,0 +1,11 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'indexOfFirst{}'"
fun foo(list: List<String>) {
var result = -1
<caret>for ((index, s) in list.withIndex()) {
if (s.length > 0) {
result = index
break
}
}
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'indexOfFirst{}'"
fun foo(list: List<String>) {
val <caret>result = list.indexOfFirst { it.length > 0 }
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'indexOfFirst{}'"
fun foo(list: List<String>): Int {
<caret>for ((index, s) in list.withIndex()) {
if (s.length > 0) {
return index
}
}
return -1
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'indexOfFirst{}'"
fun foo(list: List<String>): Int {
<caret>return list.indexOfFirst { it.length > 0 }
}
@@ -0,0 +1,11 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
fun foo(list: List<String>) {
var result = -1
<caret>for ((index, s) in list.withIndex()) {
if (s.length > index) {
result = index
break
}
}
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'indexOfLast{}'"
fun foo(list: List<String>) {
var result = -1
<caret>for ((index, s) in list.withIndex()) {
if (s.length > 0) {
result = index
}
}
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'indexOfLast{}'"
fun foo(list: List<String>) {
val <caret>result = list.indexOfLast { it.length > 0 }
}