Remove explicit lambda parameter types: destructuring support #KT-15162 Fixed

Also #KT-14993 Fixed
This commit is contained in:
Mikhail Glukhikh
2017-01-25 13:53:06 +03:00
parent 2c17773715
commit f4513e9c70
8 changed files with 47 additions and 1 deletions
@@ -31,7 +31,9 @@ class RemoveExplicitLambdaParameterTypesIntention : SelfTargetingIntention<KtLam
override fun applyTo(element: KtLambdaExpression, editor: Editor?) {
val oldParameterList = element.functionLiteral.valueParameterList!!
val parameterString = oldParameterList.parameters.map { it.name }.joinToString(", ")
val parameterString = oldParameterList.parameters.map {
it.destructuringDeclaration?.text ?: it.name
}.joinToString(", ")
val newParameterList = KtPsiFactory(element).createLambdaParameterList(parameterString)
oldParameterList.replace(newParameterList)
}
@@ -0,0 +1,5 @@
data class DataIntString(var i: Int, var s: String)
fun destruct(i: Int, s: String, lambda: (DataIntString) -> Unit) = lambda(DataIntString(i, s))
fun useDestruct() {
destruct(0, "a") { (x, y): DataIntString<caret> -> }
}
@@ -0,0 +1,5 @@
data class DataIntString(var i: Int, var s: String)
fun destruct(i: Int, s: String, lambda: (DataIntString) -> Unit) = lambda(DataIntString(i, s))
fun useDestruct() {
destruct(0, "a") { (x, y) -> }
}
@@ -0,0 +1,5 @@
data class DataIntString(var i: Int, var s: String)
fun destruct(i: Int, s: String, lambda: (DataIntString, Int) -> Unit) = lambda(DataIntString(i, s), i)
fun useDestruct() {
destruct(0, "a") { (x, y): DataIntString, i: Int<caret> -> }
}
@@ -0,0 +1,5 @@
data class DataIntString(var i: Int, var s: String)
fun destruct(i: Int, s: String, lambda: (DataIntString, Int) -> Unit) = lambda(DataIntString(i, s), i)
fun useDestruct() {
destruct(0, "a") { (x, y), i -> }
}
@@ -0,0 +1,3 @@
data class A(val x: String, val y: String)
fun foo(a: A, block: (Int, A, String) -> String): String = block(1, a, "#")
fun bb() = foo(A("O", "K")) { i: <caret>Int, (x, y):A, v:String -> i.toString() + x + y + v }
@@ -0,0 +1,3 @@
data class A(val x: String, val y: String)
fun foo(a: A, block: (Int, A, String) -> String): String = block(1, a, "#")
fun bb() = foo(A("O", "K")) { i, (x, y), v -> i.toString() + x + y + v }
@@ -11847,6 +11847,24 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeExplicitLambdaParameterTypes/typesAlreadyImplicit.kt");
doTest(fileName);
}
@TestMetadata("withDestructuring.kt")
public void testWithDestructuring() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeExplicitLambdaParameterTypes/withDestructuring.kt");
doTest(fileName);
}
@TestMetadata("withDestructuringAndSimple.kt")
public void testWithDestructuringAndSimple() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeExplicitLambdaParameterTypes/withDestructuringAndSimple.kt");
doTest(fileName);
}
@TestMetadata("withDestructuringInMiddle.kt")
public void testWithDestructuringInMiddle() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeExplicitLambdaParameterTypes/withDestructuringInMiddle.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/intentions/removeExplicitSuperQualifier")