"Replace 'invoke' with direct call" intention: do not add unnecessary parenthesis
#KT-37967 Fixed
This commit is contained in:
committed by
Vladimir Dolzhenko
parent
2f29b38b19
commit
9b3c3ae4ba
@@ -455,15 +455,21 @@ public class KtPsiUtil {
|
||||
|
||||
if (parentElement instanceof KtCallExpression && currentInner == ((KtCallExpression) parentElement).getCalleeExpression()) {
|
||||
KtCallExpression parentCall = (KtCallExpression) parentElement;
|
||||
if (innerExpression instanceof KtSimpleNameExpression) return false;
|
||||
KtExpression targetInnerExpression = innerExpression;
|
||||
if (targetInnerExpression instanceof KtDotQualifiedExpression) {
|
||||
KtExpression selector = ((KtDotQualifiedExpression) targetInnerExpression).getSelectorExpression();
|
||||
if (selector != null) {
|
||||
targetInnerExpression = selector;
|
||||
}
|
||||
}
|
||||
if (targetInnerExpression instanceof KtSimpleNameExpression) return false;
|
||||
if (KtPsiUtilKt.getQualifiedExpressionForSelector(parentElement) != null) return true;
|
||||
if (innerExpression instanceof KtCallExpression
|
||||
&& parentCall.getValueArgumentList() == null) return true;
|
||||
return !(innerExpression instanceof KtThisExpression
|
||||
|| innerExpression instanceof KtArrayAccessExpression
|
||||
|| innerExpression instanceof KtConstantExpression
|
||||
|| innerExpression instanceof KtStringTemplateExpression
|
||||
|| innerExpression instanceof KtCallExpression);
|
||||
if (targetInnerExpression instanceof KtCallExpression && parentCall.getValueArgumentList() == null) return true;
|
||||
return !(targetInnerExpression instanceof KtThisExpression
|
||||
|| targetInnerExpression instanceof KtArrayAccessExpression
|
||||
|| targetInnerExpression instanceof KtConstantExpression
|
||||
|| targetInnerExpression instanceof KtStringTemplateExpression
|
||||
|| targetInnerExpression instanceof KtCallExpression);
|
||||
}
|
||||
|
||||
if (parentElement instanceof KtValueArgument) {
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
class A {
|
||||
val b = B()
|
||||
}
|
||||
|
||||
class B {
|
||||
operator fun invoke() {}
|
||||
}
|
||||
|
||||
fun test(a: A) {
|
||||
a.b.<caret>invoke()
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
class A {
|
||||
val b = B()
|
||||
}
|
||||
|
||||
class B {
|
||||
operator fun invoke() {}
|
||||
}
|
||||
|
||||
fun test(a: A) {
|
||||
a.b()
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
class A {
|
||||
fun b() = B()
|
||||
}
|
||||
|
||||
class B {
|
||||
operator fun invoke() {}
|
||||
}
|
||||
|
||||
fun test(a: A) {
|
||||
a.b().<caret>invoke()
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
class A {
|
||||
fun b() = B()
|
||||
}
|
||||
|
||||
class B {
|
||||
operator fun invoke() {}
|
||||
}
|
||||
|
||||
fun test(a: A) {
|
||||
a.b()()
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
class A {
|
||||
fun b() = B()
|
||||
}
|
||||
|
||||
class B {
|
||||
operator fun invoke(f: () -> Unit) {}
|
||||
}
|
||||
|
||||
fun test(a: A) {
|
||||
a.b().<caret>invoke {
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
class A {
|
||||
fun b() = B()
|
||||
}
|
||||
|
||||
class B {
|
||||
operator fun invoke(f: () -> Unit) {}
|
||||
}
|
||||
|
||||
fun test(a: A) {
|
||||
(a.b()) {
|
||||
}
|
||||
}
|
||||
@@ -3910,6 +3910,21 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/intentions/conventionNameCalls/replaceInvoke"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("dotQualifiedReceiver.kt")
|
||||
public void testDotQualifiedReceiver() throws Exception {
|
||||
runTest("idea/testData/intentions/conventionNameCalls/replaceInvoke/dotQualifiedReceiver.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("dotQualifiedReceiver2.kt")
|
||||
public void testDotQualifiedReceiver2() throws Exception {
|
||||
runTest("idea/testData/intentions/conventionNameCalls/replaceInvoke/dotQualifiedReceiver2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("dotQualifiedReceiver3.kt")
|
||||
public void testDotQualifiedReceiver3() throws Exception {
|
||||
runTest("idea/testData/intentions/conventionNameCalls/replaceInvoke/dotQualifiedReceiver3.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("expressionReceiver.kt")
|
||||
public void testExpressionReceiver() throws Exception {
|
||||
runTest("idea/testData/intentions/conventionNameCalls/replaceInvoke/expressionReceiver.kt");
|
||||
|
||||
Reference in New Issue
Block a user