diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt index 289cd2ca316..53b8489c90d 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt @@ -38,7 +38,6 @@ import org.jetbrains.kotlin.resolve.calls.inference.wrapWithCapturingSubstitutio import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver import org.jetbrains.kotlin.resolve.sam.* import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter -import org.jetbrains.kotlin.resolve.scopes.ResolutionScope import org.jetbrains.kotlin.resolve.scopes.SyntheticScope import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.types.* @@ -168,19 +167,24 @@ class SamAdapterFunctionsScope( } } - override fun getSyntheticStaticFunctions(scope: ResolutionScope, name: Name, location: LookupLocation): Collection { + override fun getSyntheticStaticFunctions( + contributedFunctions: Collection, + location: LookupLocation + ): Collection { if (!shouldGenerateAdditionalSamCandidate) return emptyList() - return getSamFunctions(scope.getContributedFunctions(name, location), location) + return getSamFunctions(contributedFunctions, location) } - override fun getSyntheticConstructors(scope: ResolutionScope, name: Name, location: LookupLocation): Collection { - val classifier = scope.getContributedClassifier(name, location) ?: return emptyList() - recordSamLookupsToClassifier(classifier, location) + override fun getSyntheticConstructors( + contributedClassifier: ClassifierDescriptor, + location: LookupLocation + ): Collection { + recordSamLookupsToClassifier(contributedClassifier, location) - if (!shouldGenerateAdditionalSamCandidate) return listOfNotNull(getSamConstructor(classifier)) + if (!shouldGenerateAdditionalSamCandidate) return listOfNotNull(getSamConstructor(contributedClassifier)) - return getAllSamConstructors(classifier) + return getAllSamConstructors(contributedClassifier) } private fun recordSamLookupsToClassifier(classifier: ClassifierDescriptor, location: LookupLocation) { @@ -191,14 +195,14 @@ class SamAdapterFunctionsScope( lookupTracker.record(location, classifier, SAM_LOOKUP_NAME) } - override fun getSyntheticStaticFunctions(scope: ResolutionScope): Collection { + override fun getSyntheticStaticFunctions(functionDescriptors: Collection): Collection { if (!shouldGenerateAdditionalSamCandidate) return emptyList() - return getSamFunctions(scope.getContributedDescriptors(DescriptorKindFilter.FUNCTIONS), location = null) + return getSamFunctions(functionDescriptors, location = null) } - override fun getSyntheticConstructors(scope: ResolutionScope): Collection { - val classifiers = scope.getContributedDescriptors(DescriptorKindFilter.CLASSIFIERS).filterIsInstance() + override fun getSyntheticConstructors(classifierDescriptors: Collection): Collection { + val classifiers = classifierDescriptors.filterIsInstance() if (!shouldGenerateAdditionalSamCandidate) return classifiers.mapNotNull { getSamConstructor(it) } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt index 80817debabe..88f23c7a361 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt @@ -23,7 +23,10 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.getReceiverValueWithSmartCa import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForTypeAliasObject import org.jetbrains.kotlin.resolve.calls.util.isLowPriorityFromStdlibJre7Or8 -import org.jetbrains.kotlin.resolve.descriptorUtil.* +import org.jetbrains.kotlin.resolve.descriptorUtil.HIDES_MEMBERS_NAME_LIST +import org.jetbrains.kotlin.resolve.descriptorUtil.hasClassValueDescriptor +import org.jetbrains.kotlin.resolve.descriptorUtil.hasHidesMembersAnnotation +import org.jetbrains.kotlin.resolve.descriptorUtil.hasLowPriorityInOverloadResolution import org.jetbrains.kotlin.resolve.scopes.* import org.jetbrains.kotlin.resolve.scopes.receivers.CastImplicitClassReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitClassReceiver @@ -36,7 +39,6 @@ import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.typeUtil.getImmediateSuperclassNotAny import org.jetbrains.kotlin.utils.SmartList import org.jetbrains.kotlin.utils.addIfNotNull -import kotlin.collections.ArrayList internal abstract class AbstractScopeTowerLevel( protected val scopeTower: ImplicitScopeTower @@ -382,14 +384,18 @@ private fun ResolutionScope.getContributedFunctionsAndConstructors( extensionReceiver: ReceiverValueWithSmartCastInfo?, scopeTower: ImplicitScopeTower ): Collection { - val result = ArrayList(getContributedFunctions(name, location)) + val contributedFunctions = getContributedFunctions(name, location) + + val result = ArrayList(contributedFunctions) getContributedClassifier(name, location)?.let { result.addAll(getConstructorsOfClassifier(it)) + result.addAll(scopeTower.syntheticScopes.collectSyntheticConstructors(it, location)) } - result.addAll(scopeTower.syntheticScopes.collectSyntheticStaticFunctions(this, name, location)) - result.addAll(scopeTower.syntheticScopes.collectSyntheticConstructors(this, name, location)) + if (contributedFunctions.isNotEmpty()) { + result.addAll(scopeTower.syntheticScopes.collectSyntheticStaticFunctions(contributedFunctions, location)) + } return scopeTower.interceptFunctionCandidates(this, name, result, location, dispatchReceiver, extensionReceiver) } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/SyntheticScopes.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/SyntheticScopes.kt index 039f25a072d..c45e8ea9cc3 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/SyntheticScopes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/SyntheticScopes.kt @@ -17,9 +17,7 @@ package org.jetbrains.kotlin.resolve.scopes import org.jetbrains.kotlin.container.DefaultImplementation -import org.jetbrains.kotlin.descriptors.ConstructorDescriptor -import org.jetbrains.kotlin.descriptors.FunctionDescriptor -import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.scopes.synthetic.FunInterfaceConstructorsScopeProvider @@ -27,19 +25,21 @@ import org.jetbrains.kotlin.types.KotlinType interface SyntheticScope { + fun getSyntheticExtensionProperties(receiverTypes: Collection, name: Name, location: LookupLocation): Collection fun getSyntheticMemberFunctions(receiverTypes: Collection, name: Name, location: LookupLocation): Collection - fun getSyntheticStaticFunctions(scope: ResolutionScope, name: Name, location: LookupLocation): Collection - fun getSyntheticConstructors(scope: ResolutionScope, name: Name, location: LookupLocation): Collection + fun getSyntheticStaticFunctions(contributedFunctions: Collection, location: LookupLocation): Collection + fun getSyntheticConstructors(contributedClassifier: ClassifierDescriptor, location: LookupLocation): Collection fun getSyntheticExtensionProperties(receiverTypes: Collection, location: LookupLocation): Collection fun getSyntheticMemberFunctions(receiverTypes: Collection): Collection - fun getSyntheticStaticFunctions(scope: ResolutionScope): Collection - fun getSyntheticConstructors(scope: ResolutionScope): Collection + fun getSyntheticStaticFunctions(functionDescriptors: Collection): Collection + fun getSyntheticConstructors(classifierDescriptors: Collection): Collection fun getSyntheticConstructor(constructor: ConstructorDescriptor): ConstructorDescriptor? open class Default : SyntheticScope { + override fun getSyntheticExtensionProperties( receiverTypes: Collection, name: Name, @@ -57,16 +57,14 @@ interface SyntheticScope { } override fun getSyntheticStaticFunctions( - scope: ResolutionScope, - name: Name, + contributedFunctions: Collection, location: LookupLocation ): Collection { return emptyList() } override fun getSyntheticConstructors( - scope: ResolutionScope, - name: Name, + contributedClassifier: ClassifierDescriptor, location: LookupLocation ): Collection { return emptyList() @@ -83,11 +81,11 @@ interface SyntheticScope { return emptyList() } - override fun getSyntheticStaticFunctions(scope: ResolutionScope): Collection { + override fun getSyntheticStaticFunctions(functionDescriptors: Collection): Collection { return emptyList() } - override fun getSyntheticConstructors(scope: ResolutionScope): Collection { + override fun getSyntheticConstructors(classifierDescriptors: Collection): Collection { return emptyList() } @@ -106,18 +104,17 @@ interface SyntheticScopes { } } - fun SyntheticScopes.collectSyntheticExtensionProperties(receiverTypes: Collection, name: Name, location: LookupLocation) = scopes.flatMap { it.getSyntheticExtensionProperties(receiverTypes, name, location) } fun SyntheticScopes.collectSyntheticMemberFunctions(receiverTypes: Collection, name: Name, location: LookupLocation) = scopes.flatMap { it.getSyntheticMemberFunctions(receiverTypes, name, location) } -fun SyntheticScopes.collectSyntheticStaticFunctions(scope: ResolutionScope, name: Name, location: LookupLocation) - = scopes.flatMap { it.getSyntheticStaticFunctions(scope, name, location) } +fun SyntheticScopes.collectSyntheticStaticFunctions(contributedFunctions: Collection, location: LookupLocation) + = scopes.flatMap { it.getSyntheticStaticFunctions(contributedFunctions, location,) } -fun SyntheticScopes.collectSyntheticConstructors(scope: ResolutionScope, name: Name, location: LookupLocation) - = scopes.flatMap { it.getSyntheticConstructors(scope, name, location) } +fun SyntheticScopes.collectSyntheticConstructors(contributedClassifier: ClassifierDescriptor, location: LookupLocation) + = scopes.flatMap { it.getSyntheticConstructors(contributedClassifier, location) } fun SyntheticScopes.collectSyntheticExtensionProperties(receiverTypes: Collection, location: LookupLocation) = scopes.flatMap { it.getSyntheticExtensionProperties(receiverTypes, location) } @@ -125,11 +122,11 @@ fun SyntheticScopes.collectSyntheticExtensionProperties(receiverTypes: Collectio fun SyntheticScopes.collectSyntheticMemberFunctions(receiverTypes: Collection) = scopes.flatMap { it.getSyntheticMemberFunctions(receiverTypes) } -fun SyntheticScopes.collectSyntheticStaticFunctions(scope: ResolutionScope) - = scopes.flatMap { it.getSyntheticStaticFunctions(scope) } +fun SyntheticScopes.collectSyntheticStaticFunctions(functionDescriptors: Collection) + = scopes.flatMap { it.getSyntheticStaticFunctions(functionDescriptors) } -fun SyntheticScopes.collectSyntheticConstructors(scope: ResolutionScope) - = scopes.flatMap { it.getSyntheticConstructors(scope) } +fun SyntheticScopes.collectSyntheticConstructors(classifierDescriptors: Collection) + = scopes.flatMap { it.getSyntheticConstructors(classifierDescriptors) } fun SyntheticScopes.collectSyntheticConstructors(constructor: ConstructorDescriptor) = scopes.mapNotNull { it.getSyntheticConstructor(constructor) } \ No newline at end of file diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/synthetic/FunInterfaceConstructorsSyntheticScope.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/synthetic/FunInterfaceConstructorsSyntheticScope.kt index cb41c3441d7..14936736692 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/synthetic/FunInterfaceConstructorsSyntheticScope.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/synthetic/FunInterfaceConstructorsSyntheticScope.kt @@ -5,17 +5,11 @@ package org.jetbrains.kotlin.resolve.scopes.synthetic -import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.descriptors.ClassifierDescriptor -import org.jetbrains.kotlin.descriptors.FunctionDescriptor -import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor +import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.LookupTracker import org.jetbrains.kotlin.incremental.record -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.sam.* -import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter -import org.jetbrains.kotlin.resolve.scopes.ResolutionScope import org.jetbrains.kotlin.resolve.scopes.SyntheticScope import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes import org.jetbrains.kotlin.storage.StorageManager @@ -44,16 +38,17 @@ class FunInterfaceConstructorsSyntheticScope( createSamConstructorFunction(classifier.containingDeclaration, classifier, samResolver, samConversionOracle) } - override fun getSyntheticConstructors(scope: ResolutionScope, name: Name, location: LookupLocation): Collection { - val classifier = scope.getContributedClassifier(name, location) ?: return emptyList() - recordSamLookupsToClassifier(classifier, location) + override fun getSyntheticConstructors( + contributedClassifier: ClassifierDescriptor, + location: LookupLocation + ): Collection { + recordSamLookupsToClassifier(contributedClassifier, location) - return listOfNotNull(getSamConstructor(classifier)) + return listOfNotNull(getSamConstructor(contributedClassifier)) } - override fun getSyntheticConstructors(scope: ResolutionScope): Collection = - scope.getContributedDescriptors(DescriptorKindFilter.CLASSIFIERS) - .filterIsInstanceMapNotNull { getSamConstructor(it) } + override fun getSyntheticConstructors(classifierDescriptors: Collection): Collection = + classifierDescriptors.filterIsInstanceMapNotNull { getSamConstructor(it) } private fun getSamConstructor(classifier: ClassifierDescriptor): SamConstructorDescriptor? { if (classifier is TypeAliasDescriptor) { diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/codeInsight/ReferenceVariantsHelper.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/codeInsight/ReferenceVariantsHelper.kt index edd5897faa4..e53289ab831 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/idea/codeInsight/ReferenceVariantsHelper.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/codeInsight/ReferenceVariantsHelper.kt @@ -469,9 +469,11 @@ fun ResolutionScope.collectSyntheticStaticMembersAndConstructors( nameFilter: (Name) -> Boolean ): List { val syntheticScopes = resolutionFacade.getFrontendService(SyntheticScopes::class.java) - return (syntheticScopes.forceEnableSamAdapters().collectSyntheticStaticFunctions(this) + syntheticScopes.collectSyntheticConstructors( - this - )).filter { kindFilter.accepts(it) && nameFilter(it.name) } + val functionDescriptors = getContributedDescriptors(DescriptorKindFilter.FUNCTIONS) + val classifierDescriptors = getContributedDescriptors(DescriptorKindFilter.CLASSIFIERS) + return (syntheticScopes.forceEnableSamAdapters().collectSyntheticStaticFunctions(functionDescriptors) + + syntheticScopes.collectSyntheticConstructors(classifierDescriptors)) + .filter { kindFilter.accepts(it) && nameFilter(it.name) } } // New Inference disables scope with synthetic SAM-adapters because it uses conversions for resolution diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt index 9260bb0872d..5a107aafacd 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt @@ -471,7 +471,9 @@ class KotlinIndicesHelper( // SAM-adapter val syntheticScopes = resolutionFacade.getFrontendService(SyntheticScopes::class.java).forceEnableSamAdapters() - syntheticScopes.collectSyntheticStaticFunctions(container.staticScope, descriptor.name, NoLookupLocation.FROM_IDE) + val contributedFunctions = container.staticScope.getContributedFunctions(descriptor.name, NoLookupLocation.FROM_IDE) + + syntheticScopes.collectSyntheticStaticFunctions(contributedFunctions, NoLookupLocation.FROM_IDE) .filterIsInstance>() .firstOrNull { it.baseDescriptorForSynthetic.original == descriptor.original } ?.let { processor(it) }