diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt index cd37a212577..7cdb7d86cc0 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt @@ -27,8 +27,8 @@ import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.DescriptorUtils +import org.jetbrains.kotlin.resolve.scopes.BaseImportingScope import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter -import org.jetbrains.kotlin.resolve.scopes.ImportingScope import org.jetbrains.kotlin.resolve.scopes.LexicalScope import org.jetbrains.kotlin.resolve.scopes.utils.collectSyntheticExtensionProperties import org.jetbrains.kotlin.storage.StorageManager @@ -69,7 +69,7 @@ interface SyntheticJavaPropertyDescriptor : PropertyDescriptor { } } -class JavaSyntheticPropertiesScope(storageManager: StorageManager) : ImportingScope by ImportingScope.Empty { +class JavaSyntheticPropertiesScope(storageManager: StorageManager) : BaseImportingScope(null) { private val syntheticPropertyInClass = storageManager.createMemoizedFunctionWithNullableValues, PropertyDescriptor> { pair -> syntheticPropertyInClassNotCached(pair.first, pair.second) } 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 2616e76b801..b3a14a5a814 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt @@ -26,8 +26,8 @@ import org.jetbrains.kotlin.load.java.typeEnhacement.enhanceSignature import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf +import org.jetbrains.kotlin.resolve.scopes.BaseImportingScope import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter -import org.jetbrains.kotlin.resolve.scopes.ImportingScope import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.utils.Printer @@ -38,7 +38,7 @@ interface SamAdapterExtensionFunctionDescriptor : FunctionDescriptor { val sourceFunction: FunctionDescriptor } -class SamAdapterFunctionsScope(storageManager: StorageManager) : ImportingScope by ImportingScope.Empty { +class SamAdapterFunctionsScope(storageManager: StorageManager) : BaseImportingScope(null) { private val extensionForFunction = storageManager.createMemoizedFunctionWithNullableValues { function -> extensionForFunctionNotCached(function) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AllUnderImportsScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AllUnderImportsScope.kt index 80484a83535..cc23c22dadf 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AllUnderImportsScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AllUnderImportsScope.kt @@ -21,11 +21,11 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.PackageViewDescriptor import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.scopes.BaseImportingScope import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter -import org.jetbrains.kotlin.resolve.scopes.ImportingScope import org.jetbrains.kotlin.utils.Printer -class AllUnderImportsScope(descriptor: DeclarationDescriptor) : ImportingScope by ImportingScope.Empty { +class AllUnderImportsScope(descriptor: DeclarationDescriptor) : BaseImportingScope(null) { private val scopes = if (descriptor is ClassDescriptor) { listOf(descriptor.staticScope, descriptor.unsubstitutedInnerClassesScope) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/SingleImportScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/SingleImportScope.kt index 8ae18c205c1..b0472ec3392 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/SingleImportScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/SingleImportScope.kt @@ -19,11 +19,11 @@ package org.jetbrains.kotlin.resolve import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.scopes.BaseImportingScope import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter -import org.jetbrains.kotlin.resolve.scopes.ImportingScope import org.jetbrains.kotlin.utils.Printer -class SingleImportScope(private val aliasName: Name, private val descriptors: Collection) : ImportingScope by ImportingScope.Empty { +class SingleImportScope(private val aliasName: Name, private val descriptors: Collection) : BaseImportingScope(null) { override fun getContributedClassifier(name: Name, location: LookupLocation) = if (name == aliasName) descriptors.filterIsInstance().singleOrNull() else null diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/FileScopeProviderImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/FileScopeProviderImpl.kt index 8718dca1c53..9e6df953892 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/FileScopeProviderImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/FileScopeProviderImpl.kt @@ -29,15 +29,17 @@ import org.jetbrains.kotlin.resolve.NoSubpackagesInPackageScope import org.jetbrains.kotlin.resolve.QualifiedExpressionResolver import org.jetbrains.kotlin.resolve.TemporaryBindingTrace import org.jetbrains.kotlin.resolve.bindingContextUtil.recordScope +import org.jetbrains.kotlin.resolve.scopes.BaseLexicalScope import org.jetbrains.kotlin.resolve.scopes.ImportingScope import org.jetbrains.kotlin.resolve.scopes.LexicalScope import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope import org.jetbrains.kotlin.resolve.scopes.utils.withParent import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.getValue +import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.sure -public class FileScopeProviderImpl( +public open class FileScopeProviderImpl( private val topLevelDescriptorProvider: TopLevelDescriptorProvider, private val storageManager: StorageManager, private val moduleDescriptor: ModuleDescriptor, @@ -108,12 +110,13 @@ public class FileScopeProviderImpl( scope = LazyImportScope(scope, packageFragment, aliasImportResolver, LazyImportScope.FilteringKind.ALL, "Alias imports in $debugName") - val lexicalScope = object : LexicalScope by LexicalScope.Empty { - override val parent: LexicalScope? - get() = scope - + val lexicalScope = object : BaseLexicalScope(scope) { override val ownerDescriptor: DeclarationDescriptor get() = packageFragment + + override fun printStructure(p: Printer) { + p.println("File top-level scope (empty)") + } } bindingTrace.recordScope(lexicalScope, file) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/utils/ScopeUtils.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/utils/ScopeUtils.kt index 8cb0fb1f8d7..84c5927e9d6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/utils/ScopeUtils.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/utils/ScopeUtils.kt @@ -327,7 +327,7 @@ fun ImportingScope.withParent(newParent: ImportingScope?): ImportingScope { fun LexicalScope.replaceImportingScopes(importingScopeChain: ImportingScope?): LexicalScope { return if (this is ImportingScope) - importingScopeChain ?: LexicalScope.Empty + importingScopeChain ?: ImportingScope.Empty else LexicalScopeWrapper(this, importingScopeChain) } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/ExplicitImportsScope.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/ExplicitImportsScope.kt index a2a72b5090e..403d84c1838 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/ExplicitImportsScope.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/ExplicitImportsScope.kt @@ -22,7 +22,7 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull -public class ExplicitImportsScope(private val descriptors: Collection) : ImportingScope by ImportingScope.Empty { +public class ExplicitImportsScope(private val descriptors: Collection) : BaseImportingScope(null) { override fun getContributedClassifier(name: Name, location: LookupLocation) = descriptors.filter { it.getName() == name }.firstIsInstanceOrNull() diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt index 1dd7f9c1f4c..7fe0bdf8dc5 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt @@ -48,30 +48,6 @@ interface LexicalScope { fun getContributedFunctions(name: Name, location: LookupLocation): Collection fun printStructure(p: Printer) - - object Empty : LexicalScope { - override val parent: LexicalScope? - get() = null - - override val ownerDescriptor: DeclarationDescriptor - get() = throw UnsupportedOperationException() - - override val isOwnerDescriptorAccessibleByLabel: Boolean - get() = false - - override val implicitReceiver: ReceiverParameterDescriptor? - get() = null - - override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection = emptyList() - - override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? = null - - override fun getContributedVariables(name: Name, location: LookupLocation): Collection = emptyList() - - override fun getContributedFunctions(name: Name, location: LookupLocation): Collection = emptyList() - - override fun printStructure(p: Printer) = throw UnsupportedOperationException() - } } // TODO: common base interface instead direct inheritance @@ -94,15 +70,49 @@ interface ImportingScope : LexicalScope { fun getContributedSyntheticExtensionProperties(receiverTypes: Collection): Collection fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection): Collection - object Empty : ImportingScope, LexicalScope by LexicalScope.Empty { - override fun getContributedPackage(name: Name) = null - - override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection, name: Name, location: LookupLocation): Collection = emptyList() - - override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection, name: Name, location: LookupLocation): Collection = emptyList() - - override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection): Collection = emptyList() - - override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection): Collection = emptyList() + object Empty : BaseImportingScope(null) { + override fun printStructure(p: Printer) { + p.println("ImportingScope.Empty") + } } } + +abstract class BaseLexicalScope(override val parent: LexicalScope?) : LexicalScope { + override val isOwnerDescriptorAccessibleByLabel: Boolean + get() = false + + override val implicitReceiver: ReceiverParameterDescriptor? + get() = null + + override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection = emptyList() + + override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? = null + + override fun getContributedVariables(name: Name, location: LookupLocation): Collection = emptyList() + + override fun getContributedFunctions(name: Name, location: LookupLocation): Collection = emptyList() +} + +abstract class BaseImportingScope(parent: ImportingScope?) : BaseLexicalScope(parent), ImportingScope { + override val parent: ImportingScope? + get() = super.parent as ImportingScope? + + override val ownerDescriptor: DeclarationDescriptor + get() = throw UnsupportedOperationException() + + override final val isOwnerDescriptorAccessibleByLabel: Boolean + get() = false + + override final val implicitReceiver: ReceiverParameterDescriptor? + get() = null + + override fun getContributedPackage(name: Name): PackageViewDescriptor? = null + + override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection, name: Name, location: LookupLocation): Collection = emptyList() + + override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection, name: Name, location: LookupLocation): Collection = emptyList() + + override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection): Collection = emptyList() + + override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection): Collection = emptyList() +} \ No newline at end of file