Do not suggest removing empty parentheses if lambda is on the next line
So #KT-15195 Fixed
This commit is contained in:
+4
-1
@@ -22,6 +22,7 @@ import com.intellij.openapi.editor.Editor
|
|||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import org.jetbrains.kotlin.idea.conversion.copy.range
|
import org.jetbrains.kotlin.idea.conversion.copy.range
|
||||||
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
|
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.KtCallExpression
|
||||||
import org.jetbrains.kotlin.psi.KtValueArgumentList
|
import org.jetbrains.kotlin.psi.KtValueArgumentList
|
||||||
|
|
||||||
@@ -39,7 +40,9 @@ class RemoveEmptyParenthesesFromLambdaCallIntention : SelfTargetingRangeIntentio
|
|||||||
override fun applicabilityRange(element: KtValueArgumentList): TextRange? {
|
override fun applicabilityRange(element: KtValueArgumentList): TextRange? {
|
||||||
if (element.arguments.isNotEmpty()) return null
|
if (element.arguments.isNotEmpty()) return null
|
||||||
val parent = element.parent as? KtCallExpression ?: 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?) {
|
override fun applyTo(element: KtValueArgumentList, editor: Editor?) {
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
|
||||||
|
fun foo(f: (Int) -> Unit) = f(4)
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
foo()<caret>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
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")
|
@TestMetadata("simple.kt")
|
||||||
public void testSimple() throws Exception {
|
public void testSimple() throws Exception {
|
||||||
runTest("idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/simple.kt");
|
runTest("idea/testData/intentions/removeEmptyParenthesesFromLambdaCall/simple.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user