From fad4261448261e0c8177123ca8ed3fa416aaddcb Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Fri, 31 Oct 2014 14:48:13 +0300 Subject: [PATCH] KT-6132 No smart completion for argument of java static method #KT-6132 Fixed --- .../jet/lang/resolve/scopes/receivers/Qualifier.kt | 4 ++-- .../org/jetbrains/jet/plugin/completion/ExpectedInfos.kt | 7 +++++-- .../FunctionFromAnotherPackage.kt | 8 ++++++++ .../smartMultiFile/FunctionFromAnotherPackage/Package.kt | 3 +++ .../completion/MultiFileSmartCompletionTestGenerated.java | 7 +++++++ 5 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 idea/testData/completion/smartMultiFile/FunctionFromAnotherPackage/FunctionFromAnotherPackage.kt create mode 100644 idea/testData/completion/smartMultiFile/FunctionFromAnotherPackage/Package.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/receivers/Qualifier.kt b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/receivers/Qualifier.kt index 9bf3063aa4a..d075d2f186e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/receivers/Qualifier.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/receivers/Qualifier.kt @@ -35,7 +35,7 @@ import org.jetbrains.jet.lang.psi.JetExpression import org.jetbrains.jet.lang.resolve.bindingContextUtil.recordScopeAndDataFlowInfo import kotlin.properties.Delegates -public trait Qualifier { +public trait Qualifier: ReceiverValue { public val expression: JetExpression @@ -56,7 +56,7 @@ class QualifierReceiver ( val referenceExpression: JetSimpleNameExpression, override val packageView: PackageViewDescriptor?, override val classifier: ClassifierDescriptor? -) : Qualifier, ReceiverValue { +) : Qualifier { override val expression: JetExpression = referenceExpression.getTopmostParentQualifiedExpressionForSelector() ?: referenceExpression diff --git a/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt b/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt index 2838b3989db..c6c79203387 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt @@ -68,6 +68,8 @@ import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor import org.jetbrains.jet.plugin.project.ResolveSessionForBodies import org.jetbrains.jet.lang.descriptors.VariableDescriptor import org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus +import org.jetbrains.jet.lang.resolve.scopes.receivers.Qualifier +import org.jetbrains.jet.lang.resolve.scopes.receivers.QualifierReceiver enum class Tail { COMMA @@ -132,12 +134,13 @@ class ExpectedInfos(val bindingContext: BindingContext, val resolveSession: Reso if (parent is JetQualifiedExpression && callElement == parent.getSelectorExpression()) { val receiverExpression = parent.getReceiverExpression() val expressionType = bindingContext[BindingContext.EXPRESSION_TYPE, receiverExpression] + val qualifier = bindingContext[BindingContext.QUALIFIER, receiverExpression] if (expressionType != null) { receiver = ExpressionReceiver(receiverExpression, expressionType) callOperationNode = parent.getOperationTokenNode() } - else if (bindingContext[BindingContext.QUALIFIER, receiverExpression] != null) { - receiver = ReceiverValue.NO_RECEIVER + else if (qualifier != null) { + receiver = qualifier callOperationNode = null } else { diff --git a/idea/testData/completion/smartMultiFile/FunctionFromAnotherPackage/FunctionFromAnotherPackage.kt b/idea/testData/completion/smartMultiFile/FunctionFromAnotherPackage/FunctionFromAnotherPackage.kt new file mode 100644 index 00000000000..bec55ae47d1 --- /dev/null +++ b/idea/testData/completion/smartMultiFile/FunctionFromAnotherPackage/FunctionFromAnotherPackage.kt @@ -0,0 +1,8 @@ +package p1 + +fun test(s: String, i: Int) { + p2.foo() + +fun foo(i: Int) = i + +// EXIST: s \ No newline at end of file diff --git a/idea/testData/completion/smartMultiFile/FunctionFromAnotherPackage/Package.kt b/idea/testData/completion/smartMultiFile/FunctionFromAnotherPackage/Package.kt new file mode 100644 index 00000000000..195dd80a073 --- /dev/null +++ b/idea/testData/completion/smartMultiFile/FunctionFromAnotherPackage/Package.kt @@ -0,0 +1,3 @@ +package p2 + +fun foo(s: String) {} diff --git a/idea/tests/org/jetbrains/jet/completion/MultiFileSmartCompletionTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/MultiFileSmartCompletionTestGenerated.java index b2f88308c1e..7e6aa4277e6 100644 --- a/idea/tests/org/jetbrains/jet/completion/MultiFileSmartCompletionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/completion/MultiFileSmartCompletionTestGenerated.java @@ -19,6 +19,7 @@ package org.jetbrains.jet.completion; import com.intellij.testFramework.TestDataPath; import org.jetbrains.jet.JUnit3RunnerWithInners; import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.test.InnerTestClasses; import org.jetbrains.jet.test.TestMetadata; import org.junit.runner.RunWith; @@ -35,6 +36,12 @@ public class MultiFileSmartCompletionTestGenerated extends AbstractMultiFileSmar JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/completion/smartMultiFile"), Pattern.compile("^([^\\.]+)$"), false); } + @TestMetadata("FunctionFromAnotherPackage") + public void testFunctionFromAnotherPackage() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smartMultiFile/FunctionFromAnotherPackage/"); + doTest(fileName); + } + @TestMetadata("JavaStaticMethodArgument") public void testJavaStaticMethodArgument() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smartMultiFile/JavaStaticMethodArgument/");