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 c70b03e8278..624c0500b7c 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 @@ -164,7 +164,7 @@ class SmartCompletion( } if (callTypeAndReceiver is CallTypeAndReceiver.DEFAULT) { - toCallableReferenceLookupElement(descriptor, callableTypeExpectedInfo)?.let { result.add(it) } + toCallableReferenceLookupElement(descriptor)?.let { result.add(it) } } return result @@ -315,14 +315,13 @@ class SmartCompletion( return null } - private fun toCallableReferenceLookupElement(descriptor: DeclarationDescriptor, - functionExpectedInfos: Collection): LookupElement? { - if (functionExpectedInfos.isEmpty()) return null + private fun toCallableReferenceLookupElement(descriptor: DeclarationDescriptor): LookupElement? { + if (callableTypeExpectedInfo.isEmpty()) return null fun toLookupElement(descriptor: CallableDescriptor): LookupElement? { val callableReferenceType = descriptor.callableReferenceType(resolutionFacade) ?: return null - val matchedExpectedInfos = functionExpectedInfos.filter { it.matchingSubstitutor(callableReferenceType) != null } + val matchedExpectedInfos = callableTypeExpectedInfo.filter { it.matchingSubstitutor(callableReferenceType) != null } if (matchedExpectedInfos.isEmpty()) return null var lookupElement = lookupElementFactory.createLookupElement(descriptor, useReceiverTypes = false, parametersAndTypeGrayed = true) @@ -344,14 +343,22 @@ class SmartCompletion( .addTailAndNameSimilarity(matchedExpectedInfos) } - if (descriptor is CallableDescriptor) { - return toLookupElement(descriptor) - } - 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 :: - return toLookupElement(constructors.single()) + when (descriptor) { + is CallableDescriptor -> { + if (descriptor.dispatchReceiverParameter != null || descriptor.extensionReceiverParameter != null) { + return null // members and extensions are not supported after "::" currently + } + return toLookupElement(descriptor) + } + + is ClassDescriptor -> { + if (descriptor.modality != Modality.ABSTRACT && !descriptor.isInner) { + val constructors = descriptor.getConstructors().filter(visibilityFilter) + if (constructors.size() == 1) { + //TODO: this code is to be changed if overloads to start work after :: + return toLookupElement(constructors.single()) + } + } } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletionSession.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletionSession.kt index 4fe2a7658e9..eb346d960de 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletionSession.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletionSession.kt @@ -35,7 +35,15 @@ class SmartCompletionSession(configuration: CompletionSessionConfiguration, para : CompletionSession(configuration, parameters, resultSet) { // we do not include SAM-constructors because they are handled separately and adding them requires iterating of java classes - override val descriptorKindFilter = DescriptorKindFilter.VALUES exclude SamConstructorDescriptorKindExclude + override val descriptorKindFilter: DescriptorKindFilter + get() { + var filter = DescriptorKindFilter.VALUES exclude SamConstructorDescriptorKindExclude + if (smartCompletion?.expectedInfos?.filterFunctionExpected()?.isNotEmpty() ?: false) { + // if function type is expected we need classes to obtain their constructors + filter = filter.withKinds(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS_MASK) + } + return filter + } private val smartCompletion by lazy(LazyThreadSafetyMode.NONE) { expression?.let { diff --git a/idea/idea-completion/testData/smart/callableReference/NoQualifier12.kt b/idea/idea-completion/testData/smart/callableReference/NoQualifier12.kt index ddf4f861be5..06dc37f4448 100644 --- a/idea/idea-completion/testData/smart/callableReference/NoQualifier12.kt +++ b/idea/idea-completion/testData/smart/callableReference/NoQualifier12.kt @@ -1,5 +1,6 @@ class C { - fun foo(p: C.() -> Unit){} + fun foo(p: C.() -> Any){} + fun foo(p: () -> Any){} fun bar() { foo() @@ -7,7 +8,15 @@ class C { fun f1(){} fun C.f2(){} + + inner class Inner + class Nested } -// EXIST: ::f1 +class Outer + +// ABSENT: ::f1 // ABSENT: ::f2 +// ABSENT: ::Inner +// EXIST: ::Nested +// EXIST: ::Outer