Add intention to convert lambda to anonymous function #KT-7710 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-05-07 07:30:50 +03:00
committed by Mikhail Glukhikh
parent 8ef4b9a8e1
commit 8a20d1bf01
46 changed files with 437 additions and 0 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.intentions.LambdaToAnonymousFunctionIntention
@@ -0,0 +1,5 @@
fun foo(f: (Int) -> String) {}
fun test() {
foo(<caret>{ "" })
}
@@ -0,0 +1,5 @@
fun foo(f: (Int) -> String) {}
fun test() {
foo(fun(it: Int): String { return "" })
}
@@ -0,0 +1,7 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
fun foo(f: (Pair<Int, Int>) -> String) {}
fun test() {
foo <caret>{ (i, j) -> "" }
}
@@ -0,0 +1,5 @@
fun bar(f: (Int, Int) -> String) {}
fun test() {
bar <caret>{ i, j -> "$i$j" }
}
@@ -0,0 +1,5 @@
fun bar(f: (Int, Int) -> String) {}
fun test() {
bar(fun(i: Int, j: Int): String { return "$i$j" })
}
@@ -0,0 +1,6 @@
class Foo
fun bar(f: Foo.() -> Unit) {}
fun main(args: Array<String>) {
bar {}<caret>
}
@@ -0,0 +1,6 @@
class Foo
fun bar(f: Foo.() -> Unit) {}
fun main(args: Array<String>) {
bar(fun Foo.() {})
}
@@ -0,0 +1,6 @@
class Foo
fun baz(f: Foo.(i: Int, j: Int) -> Int) {}
fun main(args: Array<String>) {
baz { i, j -> i + j }<caret>
}
@@ -0,0 +1,6 @@
class Foo
fun baz(f: Foo.(i: Int, j: Int) -> Int) {}
fun main(args: Array<String>) {
baz(fun Foo.(i: Int, j: Int): Int { return i + j })
}
@@ -0,0 +1,9 @@
fun foo(f: (Int) -> String) {}
fun test() {
foo <caret>{
// comment1
""
// comment2
}
}
@@ -0,0 +1,9 @@
fun foo(f: (Int) -> String) {}
fun test() {
foo(fun(it: Int): String {
// comment1
return ""
// comment2
})
}
@@ -0,0 +1,5 @@
fun foo(f: (Int) -> String) {}
fun test() {
foo {<caret> return@foo "$it" }
}
@@ -0,0 +1,5 @@
fun foo(f: (Int) -> String) {}
fun test() {
foo(fun(it: Int): String { return "$it" })
}
@@ -0,0 +1,10 @@
fun foo(f: (Int) -> String) {}
fun test() {
foo {
if (it == 1) {
return@foo "1"
}
"$it"
<caret>}
}
@@ -0,0 +1,10 @@
fun foo(f: (Int) -> String) {}
fun test() {
foo(fun(it: Int): String {
if (it == 1) {
return "1"
}
return "$it"
})
}
@@ -0,0 +1,13 @@
fun foo(f: (Int) -> String) {}
fun test() {
foo {
if (it == 1) {
return@foo "1"
} else if (it == 2) {
return@foo "2"
} else {
return@foo "$it"
}
}<caret>
}
@@ -0,0 +1,13 @@
fun foo(f: (Int) -> String) {}
fun test() {
foo(fun(it: Int): String {
if (it == 1) {
return "1"
} else if (it == 2) {
return "2"
} else {
return "$it"
}
})
}
@@ -0,0 +1,11 @@
// WITH_RUNTIME
fun foo(f: (Int) -> String) {}
fun test() {
foo {<caret>
listOf(1).map {
return@map 2
}
return@foo "$it"
}
}
@@ -0,0 +1,11 @@
// WITH_RUNTIME
fun foo(f: (Int) -> String) {}
fun test() {
foo(fun(it: Int): String {
listOf(1).map {
return@map 2
}
return "$it"
})
}
@@ -0,0 +1,8 @@
fun foo(f: (Int) -> String) {}
fun test() {
foo <caret>{
val b = it == 1
if (b) "1" else "2"
}
}
@@ -0,0 +1,8 @@
fun foo(f: (Int) -> String) {}
fun test() {
foo(fun(it: Int): String {
val b = it == 1
return if (b) "1" else "2"
})
}
@@ -0,0 +1,5 @@
fun foo(f: (Int) -> String) {}
fun test() {
foo <caret>{ "$it" }
}
@@ -0,0 +1,5 @@
fun foo(f: (Int) -> String) {}
fun test() {
foo(fun(it: Int): String { return "$it" })
}
@@ -0,0 +1,5 @@
fun baz(name: String, f: (Int) -> String) {}
fun test() {
baz(name = "", f = <caret>{ "$it" })
}
@@ -0,0 +1,5 @@
fun baz(name: String, f: (Int) -> String) {}
fun test() {
baz(name = "", f = fun(it: Int): String { return "$it" })
}
@@ -0,0 +1,5 @@
fun foo(f: () -> String) {}
fun test() {
foo <caret>{ "" }
}
@@ -0,0 +1,5 @@
fun foo(f: () -> String) {}
fun test() {
foo(fun(): String { return "" })
}
@@ -0,0 +1,10 @@
fun unit(f: (Int) -> Unit) {}
fun foo(i: Int) {}
fun test() {
unit {
foo(it)
foo(it)
}<caret>
}
@@ -0,0 +1,10 @@
fun unit(f: (Int) -> Unit) {}
fun foo(i: Int) {}
fun test() {
unit(fun(it: Int) {
foo(it)
foo(it)
})
}
@@ -0,0 +1,6 @@
// IS_APPLICABLE: false
fun foo(f: (Int, Int) -> String) {}
fun test() {
foo <caret>{ i, _ -> "" }
}
@@ -0,0 +1,4 @@
// IS_APPLICABLE: false
fun test() {
val a: (Int) -> String = <caret>{ "" }
}