Unnecessary parentheses in function call with lambda: simplify
Related to KT-23452
This commit is contained in:
+2
-4
@@ -44,10 +44,8 @@ class RemoveEmptyParenthesesFromLambdaCallIntention : SelfTargetingRangeIntentio
|
||||
val parent = element.parent as? KtCallExpression ?: return null
|
||||
val singleLambdaArgument = parent.lambdaArguments.singleOrNull() ?: return null
|
||||
if (element.getLineNumber(start = false) != singleLambdaArgument.getLineNumber(start = true)) return null
|
||||
val prevCall = element.getPrevSiblingIgnoringWhitespaceAndComments() as? KtCallExpression
|
||||
if (prevCall?.lambdaArguments?.let { it.size > 0 } == true
|
||||
|| prevCall?.valueArguments?.any { it.getArgumentExpression() is KtLambdaExpression } == true) return null
|
||||
return element.range
|
||||
element.getPrevSiblingIgnoringWhitespaceAndComments() as? KtCallExpression ?: return element.range
|
||||
return null
|
||||
}
|
||||
|
||||
override fun applyTo(element: KtValueArgumentList, editor: Editor?) {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
fun returnFun2(i: Int): (() -> Unit) -> Unit = {}
|
||||
|
||||
fun test22() {
|
||||
returnFun2(1)()<caret> {}
|
||||
}
|
||||
@@ -12532,6 +12532,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
runTest("idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("afterLambda3.kt")
|
||||
public void testAfterLambda3() throws Exception {
|
||||
runTest("idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda3.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInRemoveEmptyParenthesesFromLambdaCall() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/removeEmptyParenthesesFromLambdaCall"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user