diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt index 8aa702668d6..19d1fa93977 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveEmptyParenthesesFromLambdaCallIntention.kt @@ -22,6 +22,7 @@ import com.intellij.openapi.editor.Editor import com.intellij.openapi.util.TextRange 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.KtValueArgumentList @@ -39,7 +40,9 @@ class RemoveEmptyParenthesesFromLambdaCallIntention : SelfTargetingRangeIntentio override fun applicabilityRange(element: KtValueArgumentList): TextRange? { if (element.arguments.isNotEmpty()) return null val parent = element.parent as? KtCallExpression ?: return null - return if (parent.lambdaArguments.count() == 1) element.range else null + val singleLambdaArgument = parent.lambdaArguments.singleOrNull() ?: return null + if (element.getLineNumber(start = false) != singleLambdaArgument.getLineNumber(start = true)) return null + return element.range } override fun applyTo(element: KtValueArgumentList, editor: Editor?) { diff --git a/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/nextLine.kt b/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/nextLine.kt new file mode 100644 index 00000000000..4ceadaf1bdb --- /dev/null +++ b/idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/nextLine.kt @@ -0,0 +1,10 @@ +// IS_APPLICABLE: false + +fun foo(f: (Int) -> Unit) = f(4) + +fun bar() { + foo() + { + + } +} \ 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 ab02be39f40..a47fc027f21 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -12242,6 +12242,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/removeEmptyParenthesesFromLambdaCall"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); } + @TestMetadata("nextLine.kt") + public void testNextLine() throws Exception { + runTest("idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/nextLine.kt"); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { runTest("idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/simple.kt");