diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt index 6878b7b83b4..403acd09e5c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt @@ -24,7 +24,7 @@ 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.KtQualifiedExpression import org.jetbrains.kotlin.psi.KtValueArgumentList import org.jetbrains.kotlin.psi.psiUtil.getPrevSiblingIgnoringWhitespaceAndComments @@ -44,8 +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 - if (element.getPrevSiblingIgnoringWhitespaceAndComments() !is KtCallExpression) return element.range - return null + val prev = element.getPrevSiblingIgnoringWhitespaceAndComments() + if (prev is KtCallExpression || (prev as? KtQualifiedExpression)?.callExpression != null) return null + return element.range } override fun applyTo(element: KtValueArgumentList, editor: Editor?) { diff --git a/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda4.kt b/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda4.kt new file mode 100644 index 00000000000..12cc4fa0d8a --- /dev/null +++ b/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda4.kt @@ -0,0 +1,7 @@ +// IS_APPLICABLE: false + +fun Unit.returnFun3(fn: (Unit) -> Unit): ((Unit) -> Unit) -> Unit = {} + +fun test() { + Unit.returnFun3 {} () {} +} \ No newline at end of file diff --git a/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda5.kt b/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda5.kt new file mode 100644 index 00000000000..636f3ae21d3 --- /dev/null +++ b/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda5.kt @@ -0,0 +1,7 @@ +// IS_APPLICABLE: false + +fun T.returnFun5(fn: (T) -> Boolean): ((T) -> T) -> Unit = {} + +fun test() { + 25.returnFun5 { true } () { it * 2 } +} \ No newline at end of file diff --git a/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda6.kt b/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda6.kt new file mode 100644 index 00000000000..88ae47cb355 --- /dev/null +++ b/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda6.kt @@ -0,0 +1,13 @@ +// IS_APPLICABLE: false + +object A { + object B { + class C { + fun returnFun(fn: () -> Unit): (() -> Unit) -> Unit = {} + } + } +} + +fun test() { + A.B.C().returnFun {} () {} +} \ 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 887f22721bc..2004c38598d 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -12994,6 +12994,21 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda3.kt"); } + @TestMetadata("afterLambda4.kt") + public void testAfterLambda4() throws Exception { + runTest("idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda4.kt"); + } + + @TestMetadata("afterLambda5.kt") + public void testAfterLambda5() throws Exception { + runTest("idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda5.kt"); + } + + @TestMetadata("afterLambda6.kt") + public void testAfterLambda6() throws Exception { + runTest("idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/afterLambda6.kt"); + } + public void testAllFilesPresentInRemoveEmptyParenthesesFromLambdaCall() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/removeEmptyParenthesesFromLambdaCall"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); }