Remove explicit lambda parameter types: destructuring support #KT-15162 Fixed
Also #KT-14993 Fixed
This commit is contained in:
+3
-1
@@ -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)
|
||||
}
|
||||
|
||||
+5
@@ -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> -> }
|
||||
}
|
||||
+5
@@ -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) -> }
|
||||
}
|
||||
+5
@@ -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> -> }
|
||||
}
|
||||
Vendored
+5
@@ -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 -> }
|
||||
}
|
||||
+3
@@ -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 }
|
||||
Vendored
+3
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user