"Remove single lambda parameter declaration": do not suggest when lambda is directly under 'if/when'
#KT-35995 Fixed
This commit is contained in:
committed by
Ilya Kirillov
parent
352a860e46
commit
cc0cb30b53
@@ -48,6 +48,9 @@ class RemoveSingleLambdaParameterFix(element: KtParameter) : KotlinQuickFixActio
|
|||||||
|
|
||||||
val lambda = parameterList.parent.parent as? KtLambdaExpression ?: return null
|
val lambda = parameterList.parent.parent as? KtLambdaExpression ?: return null
|
||||||
|
|
||||||
|
val lambdaParent = lambda.parent
|
||||||
|
if (lambdaParent is KtWhenEntry || lambdaParent is KtContainerNodeForControlStructureBody) return null
|
||||||
|
|
||||||
val property = lambda.getStrictParentOfType<KtProperty>()
|
val property = lambda.getStrictParentOfType<KtProperty>()
|
||||||
if (property != null && property.typeReference == null) return null
|
if (property != null && property.typeReference == null) return null
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// "Remove single lambda parameter declaration" "false"
|
||||||
|
// ACTION: Add braces to 'if' statement
|
||||||
|
// ACTION: Remove explicit lambda parameter types (may break code)
|
||||||
|
// ACTION: Rename to _
|
||||||
|
fun test(i: Int) {
|
||||||
|
val p: (String) -> Boolean =
|
||||||
|
if (i == 1) { <caret>s: String -> true } else { s: String -> false }
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// "Remove single lambda parameter declaration" "true"
|
||||||
|
fun test(i: Int) {
|
||||||
|
val p: (String) -> Boolean =
|
||||||
|
if (i == 1) { { <caret>s -> true } } else { s -> false }
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// "Remove single lambda parameter declaration" "true"
|
||||||
|
fun test(i: Int) {
|
||||||
|
val p: (String) -> Boolean =
|
||||||
|
if (i == 1) { { true } } else { s -> false }
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// "Remove single lambda parameter declaration" "false"
|
||||||
|
// ACTION: Add braces to 'when' entry
|
||||||
|
// ACTION: Remove explicit lambda parameter types (may break code)
|
||||||
|
// ACTION: Rename to _
|
||||||
|
fun test(i: Int) {
|
||||||
|
val p: (String) -> Boolean =
|
||||||
|
when (i) {
|
||||||
|
1 -> { <caret>s: String -> true }
|
||||||
|
else -> { s: String -> false }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// "Remove single lambda parameter declaration" "true"
|
||||||
|
fun test(i: Int) {
|
||||||
|
val p: (String) -> Boolean =
|
||||||
|
when (i) {
|
||||||
|
1 -> { { <caret>s -> true } }
|
||||||
|
else -> { s -> false }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// "Remove single lambda parameter declaration" "true"
|
||||||
|
fun test(i: Int) {
|
||||||
|
val p: (String) -> Boolean =
|
||||||
|
when (i) {
|
||||||
|
1 -> { { true } }
|
||||||
|
else -> { s -> false }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10655,6 +10655,26 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/removeSingleLambdaParameter"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/removeSingleLambdaParameter"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inIf.kt")
|
||||||
|
public void testInIf() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/removeSingleLambdaParameter/inIf.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inIf2.kt")
|
||||||
|
public void testInIf2() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/removeSingleLambdaParameter/inIf2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inWhen.kt")
|
||||||
|
public void testInWhen() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/removeSingleLambdaParameter/inWhen.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inWhen2.kt")
|
||||||
|
public void testInWhen2() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/removeSingleLambdaParameter/inWhen2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("multiple.kt")
|
@TestMetadata("multiple.kt")
|
||||||
public void testMultiple() throws Exception {
|
public void testMultiple() throws Exception {
|
||||||
runTest("idea/testData/quickfix/removeSingleLambdaParameter/multiple.kt");
|
runTest("idea/testData/quickfix/removeSingleLambdaParameter/multiple.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user