From 123b813073e84a056ae6533fbb0609905e3d3d48 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Fri, 18 Dec 2015 14:30:33 +0300 Subject: [PATCH] 'Replace with infix call' Intention: Disable on calls without explicit receiver #KT-6332 Fixed --- .../kotlin/idea/intentions/ToInfixCallIntention.kt | 3 ++- idea/testData/intentions/toInfixCall/noExplicitReceiver.kt | 3 +++ .../kotlin/idea/intentions/IntentionTestGenerated.java | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 idea/testData/intentions/toInfixCall/noExplicitReceiver.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ToInfixCallIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ToInfixCallIntention.kt index a6523423c30..e73d82d07dd 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ToInfixCallIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ToInfixCallIntention.kt @@ -20,6 +20,7 @@ import com.intellij.openapi.editor.Editor import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelector import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode @@ -28,7 +29,7 @@ public class ToInfixCallIntention : SelfTargetingIntention(KtC val calleeExpr = element.calleeExpression as? KtNameReferenceExpression ?: return false if (!calleeExpr.textRange.containsOffset(caretOffset)) return false - val dotQualified = element.parent as? KtDotQualifiedExpression ?: return false + val dotQualified = element.getQualifiedExpressionForSelector() ?: return false if (element.typeArgumentList != null) return false diff --git a/idea/testData/intentions/toInfixCall/noExplicitReceiver.kt b/idea/testData/intentions/toInfixCall/noExplicitReceiver.kt new file mode 100644 index 00000000000..0a37d9869b2 --- /dev/null +++ b/idea/testData/intentions/toInfixCall/noExplicitReceiver.kt @@ -0,0 +1,3 @@ +// IS_APPLICABLE: false +infix fun id(s: String) = s +val x = id("0").get(0) \ 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 576ab911963..34f207eef7e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -8272,6 +8272,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest { doTest(fileName); } + @TestMetadata("noExplicitReceiver.kt") + public void testNoExplicitReceiver() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/toInfixCall/noExplicitReceiver.kt"); + doTest(fileName); + } + @TestMetadata("notInfix.kt") public void testNotInfix() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/toInfixCall/notInfix.kt");