diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt index 19d1fa93977..bee3ba3d576 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt @@ -24,7 +24,9 @@ import org.jetbrains.kotlin.idea.conversion.copy.range import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection import org.jetbrains.kotlin.idea.refactoring.getLineNumber import org.jetbrains.kotlin.psi.KtCallExpression +import org.jetbrains.kotlin.psi.KtLambdaExpression import org.jetbrains.kotlin.psi.KtValueArgumentList +import org.jetbrains.kotlin.psi.psiUtil.getPrevSiblingIgnoringWhitespaceAndComments class RemoveEmptyParenthesesFromLambdaCallInspection : IntentionBasedInspection( RemoveEmptyParenthesesFromLambdaCallIntention::class @@ -42,6 +44,9 @@ 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 } diff --git a/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda.kt b/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda.kt new file mode 100644 index 00000000000..029b319353b --- /dev/null +++ b/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda.kt @@ -0,0 +1,7 @@ +// IS_APPLICABLE: false + +fun returnFun(fn: () -> Unit): (() -> Unit) -> Unit = {} + +fun test() { + returnFun {} () {} +} \ No newline at end of file diff --git a/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda2.kt b/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda2.kt new file mode 100644 index 00000000000..32a44e700af --- /dev/null +++ b/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda2.kt @@ -0,0 +1,7 @@ +// IS_APPLICABLE: false + +fun returnFun(fn: () -> Unit, i: Int): (() -> Unit) -> Unit = {} + +fun test() { + returnFun({}, 1)() {} +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index a02f491ecf1..cc8ddb9520d 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -12522,6 +12522,16 @@ public class IntentionTestGenerated extends AbstractIntentionTest { KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); } + @TestMetadata("afterLambda.kt") + public void testAfterLambda() throws Exception { + runTest("idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda.kt"); + } + + @TestMetadata("afterLambda2.kt") + public void testAfterLambda2() throws Exception { + runTest("idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda2.kt"); + } + public void testAllFilesPresentInRemoveEmptyParenthesesFromLambdaCall() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/removeEmptyParenthesesFromLambdaCall"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); }