From 683dd57f24ce8ce283cae99bb0b90b3b06e16c40 Mon Sep 17 00:00:00 2001 From: Roman Golyshev Date: Thu, 17 Sep 2020 17:23:17 +0300 Subject: [PATCH] KT-41346 Extract `Implementation` interface This is a temporary interface to make refactoring easier --- .../descriptors/DeserializedMemberScope.kt | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberScope.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberScope.kt index a536b3e8f1a..6f40d32d0ff 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberScope.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberScope.kt @@ -37,13 +37,30 @@ import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import kotlin.collections.ArrayList +private interface Implementation { + val functionNamesLazy: Set + val variableNamesLazy: Set + val typeAliasNames: Set + + fun getContributedFunctions(name: Name, location: LookupLocation): Collection + fun getContributedVariables(name: Name, location: LookupLocation): Collection + fun getTypeAliasByName(name: Name): TypeAliasDescriptor? + + fun addFunctionsAndPropertiesTo( + result: MutableCollection, + kindFilter: DescriptorKindFilter, + nameFilter: (Name) -> Boolean, + location: LookupLocation + ) +} + abstract class DeserializedMemberScope protected constructor( protected val c: DeserializationContext, functionList: Collection, propertyList: Collection, typeAliasList: Collection, classNames: () -> Collection -) : MemberScopeImpl() { +) : MemberScopeImpl(), Implementation { private val functionProtosBytes = functionList.groupByName { it.name }.packToByteArray() @@ -69,15 +86,15 @@ abstract class DeserializedMemberScope protected constructor( private val typeAliasByName = c.storageManager.createMemoizedFunctionWithNullableValues { createTypeAlias(it) } - private val functionNamesLazy by c.storageManager.createLazyValue { + override val functionNamesLazy by c.storageManager.createLazyValue { functionProtosBytes.keys + getNonDeclaredFunctionNames() } - private val variableNamesLazy by c.storageManager.createLazyValue { + override val variableNamesLazy by c.storageManager.createLazyValue { propertyProtosBytes.keys + getNonDeclaredVariableNames() } - private val typeAliasNames: Set get() = typeAliasBytes.keys + override val typeAliasNames: Set get() = typeAliasBytes.keys internal val classNames by c.storageManager.createLazyValue { classNames().toSet() } @@ -171,6 +188,10 @@ abstract class DeserializedMemberScope protected constructor( return c.memberDeserializer.loadTypeAlias(proto) } + override fun getTypeAliasByName(name: Name): TypeAliasDescriptor? { + return typeAliasByName(name) + } + override fun getContributedVariables(name: Name, location: LookupLocation): Collection { if (name !in getVariableNames()) return emptyList() return properties(name) @@ -189,7 +210,7 @@ abstract class DeserializedMemberScope protected constructor( addEnumEntryDescriptors(result, nameFilter) } - addFunctionsAndProperties(result, kindFilter, nameFilter, location) + addFunctionsAndPropertiesTo(result, kindFilter, nameFilter, location) if (kindFilter.acceptsKinds(DescriptorKindFilter.CLASSIFIERS_MASK)) { for (className in classNames) { @@ -210,7 +231,7 @@ abstract class DeserializedMemberScope protected constructor( return result.compact() } - private fun addFunctionsAndProperties( + override fun addFunctionsAndPropertiesTo( result: MutableCollection, kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean, @@ -253,7 +274,7 @@ abstract class DeserializedMemberScope protected constructor( override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? = when { hasClass(name) -> deserializeClass(name) - name in typeAliasNames -> typeAliasByName(name) + name in typeAliasNames -> getTypeAliasByName(name) else -> null }