Do not suggest removing empty parentheses if lambda is on the next line

So #KT-15195 Fixed
This commit is contained in:
Mikhail Glukhikh
2018-05-08 15:37:39 +03:00
parent 6968540889
commit 5246c54dad
3 changed files with 19 additions and 1 deletions
@@ -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?) {
@@ -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);
}
@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");