KT-14294 for to stdlib to firstOrNull/lastOrNull: intention is absent if there is additional var before for loop

#KT-14294 Fixed
This commit is contained in:
Valentin Kipyatkov
2016-10-14 21:43:47 +03:00
parent a89ef54578
commit eae23b548f
20 changed files with 287 additions and 18 deletions
@@ -0,0 +1,18 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterNotNull().firstOrNull{}'"
// INTENTION_TEXT_2: "Replace with 'asSequence().filterNotNull().firstOrNull{}'"
fun getFirstValue() = "value"
fun foo(list: List<String?>): String? {
var found: String? = null
val value = getFirstValue()
<caret>for (s in list)
if (s != null)
if(!s.startsWith("IMG:"))
if (s.contains(value)) {
found = s
break
}
return found
}
@@ -0,0 +1,13 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterNotNull().firstOrNull{}'"
// INTENTION_TEXT_2: "Replace with 'asSequence().filterNotNull().firstOrNull{}'"
fun getFirstValue() = "value"
fun foo(list: List<String?>): String? {
val value = getFirstValue()
val <caret>found: String? = list
.filterNotNull()
.firstOrNull { !it.startsWith("IMG:") && it.contains(value) }
return found
}
@@ -0,0 +1,14 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterNotNull().firstOrNull{}'"
// INTENTION_TEXT_2: "Replace with 'asSequence().filterNotNull().firstOrNull{}'"
fun getFirstValue() = "value"
fun foo(list: List<String?>): String? {
val value = getFirstValue()
val <caret>found: String? = list
.asSequence()
.filterNotNull()
.firstOrNull { !it.startsWith("IMG:") && it.contains(value) }
return found
}