Inspection for scope functions conversion

#KT-17047 Fixed
This commit is contained in:
Dmitry Jemerov
2018-01-05 15:29:58 +01:00
parent 0b24be9460
commit 60874f29fe
41 changed files with 856 additions and 26 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.ScopeFunctionConversionInspection
@@ -0,0 +1,5 @@
// WITH_RUNTIME
val x = "".<caret>also {
it.length
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
val x = "".<caret>apply {
length
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
val x = hashSetOf("abc").<caret>apply {
forEach {
forEach {
println(this)
}
}
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
val x = hashSetOf("abc").also { hashSet ->
hashSet.forEach {
hashSet.forEach {
println(hashSet)
}
}
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// FIX: Convert to 'also'
val x = "".also {
"".<caret>apply {
this.length + it.length
}
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// FIX: Convert to 'also'
val x = "".also {
"".also { s ->
s.length + it.length
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
val x = hashSetOf("abc").<caret>apply {
forEach {
println(this)
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
val x = hashSetOf("abc").also { hashSet ->
hashSet.forEach {
println(hashSet)
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
// FIX: Convert to 'also'
val x = hashSetOf<String>().<caret>apply {
add("x")
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
// FIX: Convert to 'also'
val x = hashSetOf<String>().<caret>also {
it.add("x")
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
// FIX: Convert to 'also'
val x = "".<caret>apply {
"".apply {
this.length
length
}
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
// FIX: Convert to 'also'
val x = "".<caret>also {
"".apply {
this.length
length
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// FIX: Convert to 'also'
val x = "".<caret>apply {
this.length
length
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// FIX: Convert to 'also'
val x = "".<caret>also {
it.length
it.length
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// FIX: Convert to 'also'
class C {
val x = hashSetOf<C>().<caret>apply {
add(this@C)
}
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// FIX: Convert to 'also'
class C {
val x = hashSetOf<C>().<caret>also {
it.add(this)
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
val x = hashSetOf("abc").<caret>let {
it.forEach {
println(it)
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
val x = hashSetOf("abc").<caret>run {
forEach {
println(it)
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
class C {
val c = "abc".<caret>let {
println(it + this)
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
class C {
val c = "abc".<caret>run {
println(this + this@C)
}
}
@@ -0,0 +1,15 @@
// WITH_RUNTIME
class C {
fun foo() = "c"
val bar = "C"
}
class D {
fun foo() = "d"
val bar = "D"
val x = C().<caret>let {
foo() + it.foo() + bar + it.bar
}
}
@@ -0,0 +1,15 @@
// WITH_RUNTIME
class C {
fun foo() = "c"
val bar = "C"
}
class D {
fun foo() = "d"
val bar = "D"
val x = C().<caret>run {
this@D.foo() + foo() + this@D.bar + bar
}
}
@@ -0,0 +1,15 @@
// WITH_RUNTIME
class C {
fun foo(s: String, s2: String = ""): String = "c"
val bar = "C"
}
class D {
fun baz(s: String): String = "d"
val quux = "D"
val x = C().<caret>let {
it.foo(baz(it.foo(quux + it.bar)), baz(it.bar))
}
}
@@ -0,0 +1,15 @@
// WITH_RUNTIME
class C {
fun foo(s: String, s2: String = ""): String = "c"
val bar = "C"
}
class D {
fun baz(s: String): String = "d"
val quux = "D"
val x = C().<caret>run {
foo(baz(foo(quux + bar)), baz(bar))
}
}
@@ -0,0 +1,19 @@
// WITH_RUNTIME
class C {
fun foo() = "c"
val bar = "C"
}
class D {
fun foo() = "d"
val bar = "D"
}
val d = D()
val x = d.apply {
C().<caret>let {
foo() + it.foo() + bar + it.bar
}
}
@@ -0,0 +1,19 @@
// WITH_RUNTIME
class C {
fun foo() = "c"
val bar = "C"
}
class D {
fun foo() = "d"
val bar = "D"
}
val d = D()
val x = d.apply {
C().<caret>run {
this@apply.foo() + foo() + this@apply.bar + bar
}
}
@@ -0,0 +1,19 @@
// WITH_RUNTIME
class C {
fun foo() = "c"
val bar = "C"
}
class D {
fun baz() = "d"
val quux = "D"
}
val d = D()
val x = d.apply {
C().<caret>let {
baz() + it.foo() + quux + it.bar
}
}
@@ -0,0 +1,19 @@
// WITH_RUNTIME
class C {
fun foo() = "c"
val bar = "C"
}
class D {
fun baz() = "d"
val quux = "D"
}
val d = D()
val x = d.apply {
C().<caret>run {
baz() + foo() + quux + bar
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
// FIX: Convert to 'run'
val x = "".<caret>let {
it.length
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
// FIX: Convert to 'run'
val x = "".<caret>run {
length
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
class C {
val c = "abc".<caret>let {
println("$it")
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
class C {
val c = "abc".<caret>run {
println("$this")
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// FIX: Convert to 'let'
val x = "".<caret>run {
this.length
length
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// FIX: Convert to 'let'
val x = "".<caret>let {
it.length
it.length
}