KT-41346 Extract Implementation interface
This is a temporary interface to make refactoring easier
This commit is contained in:
+28
-7
@@ -37,13 +37,30 @@ import java.io.ByteArrayInputStream
|
|||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
|
private interface Implementation {
|
||||||
|
val functionNamesLazy: Set<Name>
|
||||||
|
val variableNamesLazy: Set<Name>
|
||||||
|
val typeAliasNames: Set<Name>
|
||||||
|
|
||||||
|
fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor>
|
||||||
|
fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor>
|
||||||
|
fun getTypeAliasByName(name: Name): TypeAliasDescriptor?
|
||||||
|
|
||||||
|
fun addFunctionsAndPropertiesTo(
|
||||||
|
result: MutableCollection<DeclarationDescriptor>,
|
||||||
|
kindFilter: DescriptorKindFilter,
|
||||||
|
nameFilter: (Name) -> Boolean,
|
||||||
|
location: LookupLocation
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
abstract class DeserializedMemberScope protected constructor(
|
abstract class DeserializedMemberScope protected constructor(
|
||||||
protected val c: DeserializationContext,
|
protected val c: DeserializationContext,
|
||||||
functionList: Collection<ProtoBuf.Function>,
|
functionList: Collection<ProtoBuf.Function>,
|
||||||
propertyList: Collection<ProtoBuf.Property>,
|
propertyList: Collection<ProtoBuf.Property>,
|
||||||
typeAliasList: Collection<ProtoBuf.TypeAlias>,
|
typeAliasList: Collection<ProtoBuf.TypeAlias>,
|
||||||
classNames: () -> Collection<Name>
|
classNames: () -> Collection<Name>
|
||||||
) : MemberScopeImpl() {
|
) : MemberScopeImpl(), Implementation {
|
||||||
|
|
||||||
private val functionProtosBytes = functionList.groupByName { it.name }.packToByteArray()
|
private val functionProtosBytes = functionList.groupByName { it.name }.packToByteArray()
|
||||||
|
|
||||||
@@ -69,15 +86,15 @@ abstract class DeserializedMemberScope protected constructor(
|
|||||||
private val typeAliasByName =
|
private val typeAliasByName =
|
||||||
c.storageManager.createMemoizedFunctionWithNullableValues<Name, TypeAliasDescriptor> { createTypeAlias(it) }
|
c.storageManager.createMemoizedFunctionWithNullableValues<Name, TypeAliasDescriptor> { createTypeAlias(it) }
|
||||||
|
|
||||||
private val functionNamesLazy by c.storageManager.createLazyValue {
|
override val functionNamesLazy by c.storageManager.createLazyValue {
|
||||||
functionProtosBytes.keys + getNonDeclaredFunctionNames()
|
functionProtosBytes.keys + getNonDeclaredFunctionNames()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val variableNamesLazy by c.storageManager.createLazyValue {
|
override val variableNamesLazy by c.storageManager.createLazyValue {
|
||||||
propertyProtosBytes.keys + getNonDeclaredVariableNames()
|
propertyProtosBytes.keys + getNonDeclaredVariableNames()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val typeAliasNames: Set<Name> get() = typeAliasBytes.keys
|
override val typeAliasNames: Set<Name> get() = typeAliasBytes.keys
|
||||||
|
|
||||||
internal val classNames by c.storageManager.createLazyValue { classNames().toSet() }
|
internal val classNames by c.storageManager.createLazyValue { classNames().toSet() }
|
||||||
|
|
||||||
@@ -171,6 +188,10 @@ abstract class DeserializedMemberScope protected constructor(
|
|||||||
return c.memberDeserializer.loadTypeAlias(proto)
|
return c.memberDeserializer.loadTypeAlias(proto)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getTypeAliasByName(name: Name): TypeAliasDescriptor? {
|
||||||
|
return typeAliasByName(name)
|
||||||
|
}
|
||||||
|
|
||||||
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
|
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
|
||||||
if (name !in getVariableNames()) return emptyList()
|
if (name !in getVariableNames()) return emptyList()
|
||||||
return properties(name)
|
return properties(name)
|
||||||
@@ -189,7 +210,7 @@ abstract class DeserializedMemberScope protected constructor(
|
|||||||
addEnumEntryDescriptors(result, nameFilter)
|
addEnumEntryDescriptors(result, nameFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
addFunctionsAndProperties(result, kindFilter, nameFilter, location)
|
addFunctionsAndPropertiesTo(result, kindFilter, nameFilter, location)
|
||||||
|
|
||||||
if (kindFilter.acceptsKinds(DescriptorKindFilter.CLASSIFIERS_MASK)) {
|
if (kindFilter.acceptsKinds(DescriptorKindFilter.CLASSIFIERS_MASK)) {
|
||||||
for (className in classNames) {
|
for (className in classNames) {
|
||||||
@@ -210,7 +231,7 @@ abstract class DeserializedMemberScope protected constructor(
|
|||||||
return result.compact()
|
return result.compact()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addFunctionsAndProperties(
|
override fun addFunctionsAndPropertiesTo(
|
||||||
result: MutableCollection<DeclarationDescriptor>,
|
result: MutableCollection<DeclarationDescriptor>,
|
||||||
kindFilter: DescriptorKindFilter,
|
kindFilter: DescriptorKindFilter,
|
||||||
nameFilter: (Name) -> Boolean,
|
nameFilter: (Name) -> Boolean,
|
||||||
@@ -253,7 +274,7 @@ abstract class DeserializedMemberScope protected constructor(
|
|||||||
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? =
|
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? =
|
||||||
when {
|
when {
|
||||||
hasClass(name) -> deserializeClass(name)
|
hasClass(name) -> deserializeClass(name)
|
||||||
name in typeAliasNames -> typeAliasByName(name)
|
name in typeAliasNames -> getTypeAliasByName(name)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user