"Simplify using destructuring declaration" is now applicable for function literals #KT-13941 Fixed

This commit is contained in:
Mikhail Glukhikh
2016-10-03 12:18:29 +03:00
parent 42aea59253
commit df0cf3da84
19 changed files with 193 additions and 9 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.intentions.DestructureIntention
@@ -0,0 +1,11 @@
// WITH_RUNTIME
data class XY(val x: Int, val y: Int)
fun test(xys: Array<XY>) {
xys.forEach { xy<caret> ->
val x = xy.x
println(x)
val y = xy.y + x
println(y)
}
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
data class XY(val x: Int, val y: Int)
fun test(xys: Array<XY>) {
xys.forEach { (x, y) ->
println(x)
val y = y + x
println(y)
}
}
@@ -0,0 +1,11 @@
// WITH_RUNTIME
fun foo() {
val list = listOf(MyClass(1, 2, 3), MyClass(2, 3, 4))
list.forEach { klass<caret> ->
val a = klass.a
val b = klass.b
}
}
data class MyClass(val a: Int, val b: Int, val c: Int)
@@ -0,0 +1,9 @@
// WITH_RUNTIME
fun foo() {
val list = listOf(MyClass(1, 2, 3), MyClass(2, 3, 4))
list.forEach { (a, b) ->
}
}
data class MyClass(val a: Int, val b: Int, val c: Int)
@@ -0,0 +1,5 @@
// WITH_RUNTIME
data class XY(val x: String, val y: String)
fun foo(list: List<XY>) = list.fold("") { prev, <caret>xy -> prev + xy.x + xy.y }
@@ -0,0 +1,5 @@
// WITH_RUNTIME
data class XY(val x: String, val y: String)
fun foo(list: List<XY>) = list.fold("") { prev, (x, y) -> prev + x + y }
@@ -0,0 +1,9 @@
// WITH_RUNTIME
data class My(val first: String, val second: Int)
fun foo(list: List<My>) {
list.forEach { my<caret> ->
println(my.second)
}
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
data class My(val first: String, val second: Int)
fun foo(list: List<My>) {
list.forEach { (first, second) ->
println(second)
}
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
data class XY(val x: String, val y: String)
fun foo(list: List<XY>) = list.map { <caret>it -> it.x + it.y }
@@ -0,0 +1,5 @@
// WITH_RUNTIME
data class XY(val x: String, val y: String)
fun foo(list: List<XY>) = list.map { (x, y) -> x + y }
@@ -0,0 +1,11 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
data class XY(val x: String, val y: String)
fun test(xys: Array<XY?>) {
xys.forEach { xy<caret> ->
val x = xy?.x
val y = xy?.y
println(x + y)
}
}
@@ -0,0 +1,5 @@
data class XY(val x: String, val y: String)
fun convert(xy: XY, foo: (XY) -> String) = foo(xy)
fun foo(xy: XY) = convert(xy) { <caret>it -> it.x + it.y }
@@ -0,0 +1,5 @@
data class XY(val x: String, val y: String)
fun convert(xy: XY, foo: (XY) -> String) = foo(xy)
fun foo(xy: XY) = convert(xy) { (x, y) -> x + y }
@@ -0,0 +1,9 @@
data class XY(val x: String, val y: String)
fun convert(xy: XY, foo: (XY) -> String) = foo(xy)
fun foo(xy: XY) = convert(xy) { <caret>it ->
val x = it.x
val y = it.y
x + y
}
@@ -0,0 +1,7 @@
data class XY(val x: String, val y: String)
fun convert(xy: XY, foo: (XY) -> String) = foo(xy)
fun foo(xy: XY) = convert(xy) { (x, y) ->
x + y
}