diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletion.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletion.kt index 155f1d6bed3..c70b03e8278 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletion.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletion.kt @@ -76,6 +76,8 @@ class SmartCompletion( public val expectedInfos: Collection = calcExpectedInfos(expressionWithType) + private val callableTypeExpectedInfo = expectedInfos.filterCallableExpected() + public val smartCastCalculator: SmartCastCalculator by lazy(LazyThreadSafetyMode.NONE) { SmartCastCalculator(bindingContext, resolutionFacade.moduleDescriptor, expression) } @@ -162,7 +164,7 @@ class SmartCompletion( } if (callTypeAndReceiver is CallTypeAndReceiver.DEFAULT) { - toFunctionReferenceLookupElement(descriptor, expectedInfos.filterFunctionExpected())?.let { result.add(it) } + toCallableReferenceLookupElement(descriptor, callableTypeExpectedInfo)?.let { result.add(it) } } return result @@ -313,11 +315,11 @@ class SmartCompletion( return null } - private fun toFunctionReferenceLookupElement(descriptor: DeclarationDescriptor, + private fun toCallableReferenceLookupElement(descriptor: DeclarationDescriptor, functionExpectedInfos: Collection): LookupElement? { if (functionExpectedInfos.isEmpty()) return null - fun toLookupElement(descriptor: FunctionDescriptor): LookupElement? { + fun toLookupElement(descriptor: CallableDescriptor): LookupElement? { val callableReferenceType = descriptor.callableReferenceType(resolutionFacade) ?: return null val matchedExpectedInfos = functionExpectedInfos.filter { it.matchingSubstitutor(callableReferenceType) != null } @@ -342,10 +344,10 @@ class SmartCompletion( .addTailAndNameSimilarity(matchedExpectedInfos) } - if (descriptor is SimpleFunctionDescriptor) { + if (descriptor is CallableDescriptor) { return toLookupElement(descriptor) } - else if (descriptor is ClassDescriptor && descriptor.getModality() != Modality.ABSTRACT) { + else if (descriptor is ClassDescriptor && descriptor.modality != Modality.ABSTRACT) { val constructors = descriptor.getConstructors().filter(visibilityFilter) if (constructors.size() == 1) { //TODO: this code is to be changed if overloads to start work after :: diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt index 46e8ec5dd80..7b3d8d9a53b 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt @@ -321,3 +321,6 @@ fun DeclarationDescriptor.fuzzyTypesForSmartCompletion( fun Collection.filterFunctionExpected() = filter { it.fuzzyType != null && KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(it.fuzzyType!!.type) } +fun Collection.filterCallableExpected() + = filter { it.fuzzyType != null && ReflectionTypes.isCallableType(it.fuzzyType!!.type) } + diff --git a/idea/idea-completion/testData/smart/callableReference/NoQualifierPropertyExpected.kt b/idea/idea-completion/testData/smart/callableReference/NoQualifierPropertyExpected.kt new file mode 100644 index 00000000000..c385ac3af3f --- /dev/null +++ b/idea/idea-completion/testData/smart/callableReference/NoQualifierPropertyExpected.kt @@ -0,0 +1,16 @@ +import kotlin.reflect.KProperty + +fun foo(property: KProperty) { +} + +fun bar() { + foo() +} + +val vInt = 0 +val vString = "" +fun fInt() = 0 + +// EXIST: { lookupString: "::vInt", itemText: "::vInt", tailText: " ()", typeText: "Int" } +// ABSENT: ::vString +// ABSENT: ::fInt diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmSmartCompletionTestGenerated.java b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmSmartCompletionTestGenerated.java index 4fdf1baa16f..23f2cd88d96 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmSmartCompletionTestGenerated.java +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmSmartCompletionTestGenerated.java @@ -673,6 +673,12 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT doTest(fileName); } + @TestMetadata("NoQualifierPropertyExpected.kt") + public void testNoQualifierPropertyExpected() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/smart/callableReference/NoQualifierPropertyExpected.kt"); + doTest(fileName); + } + @TestMetadata("NonEmptyQualifier1.kt") public void testNonEmptyQualifier1() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/smart/callableReference/NonEmptyQualifier1.kt");