Refactor deserialization of nested type aliases

Do it exactly in the same way as with properties/functions, in
DeserializedMemberScope and nowhere else
This commit is contained in:
Alexander Udalov
2016-10-11 14:14:03 +03:00
parent 88af36001c
commit d96f10c7bd
3 changed files with 13 additions and 25 deletions
@@ -65,7 +65,6 @@ class DeserializedClassDescriptor(
private val containingDeclaration = outerContext.containingDeclaration private val containingDeclaration = outerContext.containingDeclaration
private val primaryConstructor = c.storageManager.createNullableLazyValue { computePrimaryConstructor() } private val primaryConstructor = c.storageManager.createNullableLazyValue { computePrimaryConstructor() }
private val constructors = c.storageManager.createLazyValue { computeConstructors() } private val constructors = c.storageManager.createLazyValue { computeConstructors() }
private val nestedTypeAliases = c.storageManager.createLazyValue { NestedTypeAliases() }
private val companionObjectDescriptor = c.storageManager.createNullableLazyValue { computeCompanionObjectDescriptor() } private val companionObjectDescriptor = c.storageManager.createNullableLazyValue { computeCompanionObjectDescriptor() }
internal val thisAsProtoContainer: ProtoContainer.Class = ProtoContainer.Class( internal val thisAsProtoContainer: ProtoContainer.Class = ProtoContainer.Class(
@@ -124,11 +123,6 @@ class DeserializedClassDescriptor(
c.memberDeserializer.loadConstructor(it, false) c.memberDeserializer.loadConstructor(it, false)
} }
private fun computeTypeAliases(): List<TypeAliasDescriptor> =
classProto.typeAliasList.map {
c.memberDeserializer.loadTypeAlias(it)
}
override fun getConstructors() = constructors() override fun getConstructors() = constructors()
private fun computeCompanionObjectDescriptor(): ClassDescriptor? { private fun computeCompanionObjectDescriptor(): ClassDescriptor? {
@@ -144,7 +138,7 @@ class DeserializedClassDescriptor(
return nestedClasses != null && name in nestedClasses.nestedClassNames return nestedClasses != null && name in nestedClasses.nestedClassNames
} }
override fun toString() = "deserialized class ${getName().toString()}" // not using descriptor render to preserve laziness override fun toString() = "deserialized class $name" // not using descriptor render to preserve laziness
override fun getSource() = sourceElement override fun getSource() = sourceElement
@@ -184,7 +178,7 @@ class DeserializedClassDescriptor(
override val annotations: Annotations get() = Annotations.EMPTY // TODO override val annotations: Annotations get() = Annotations.EMPTY // TODO
override fun toString() = getName().toString() override fun toString() = name.toString()
override val supertypeLoopChecker: SupertypeLoopChecker override val supertypeLoopChecker: SupertypeLoopChecker
// TODO: inject implementation // TODO: inject implementation
@@ -267,12 +261,11 @@ class DeserializedClassDescriptor(
recordLookup(name, location) recordLookup(name, location)
return classDescriptor.enumEntries?.findEnumEntry(name) ?: return classDescriptor.enumEntries?.findEnumEntry(name) ?:
classDescriptor.nestedClasses?.findNestedClass(name) ?: classDescriptor.nestedClasses?.findNestedClass(name) ?:
classDescriptor.nestedTypeAliases().findTypeAlias(name) getTypeAlias(name)
} }
override fun addClassifierDescriptors(result: MutableCollection<DeclarationDescriptor>, nameFilter: (Name) -> Boolean) { override fun addClassifierDescriptors(result: MutableCollection<DeclarationDescriptor>, nameFilter: (Name) -> Boolean) {
result.addAll(classDescriptor.nestedClasses?.all().orEmpty()) result.addAll(classDescriptor.nestedClasses?.all().orEmpty())
result.addAll(classDescriptor.nestedTypeAliases().all())
} }
override fun addEnumEntryDescriptors(result: MutableCollection<DeclarationDescriptor>, nameFilter: (Name) -> Boolean) { override fun addEnumEntryDescriptors(result: MutableCollection<DeclarationDescriptor>, nameFilter: (Name) -> Boolean) {
@@ -303,15 +296,6 @@ class DeserializedClassDescriptor(
nestedClassNames.mapNotNull { name -> nestedClassByName(name) } nestedClassNames.mapNotNull { name -> nestedClassByName(name) }
} }
private inner class NestedTypeAliases {
private val nestedTypeAliases = computeTypeAliases()
private val nestedTypeAliasesByName = nestedTypeAliases.associateBy { it.name }
fun all() = nestedTypeAliases
fun findTypeAlias(name: Name): TypeAliasDescriptor? = nestedTypeAliasesByName[name]
}
private inner class EnumEntryClassDescriptors { private inner class EnumEntryClassDescriptors {
private val enumEntryProtos = classProto.enumEntryList.associateBy { c.nameResolver.getName(it.name) } private val enumEntryProtos = classProto.enumEntryList.associateBy { c.nameResolver.getName(it.name) }
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.DeserializationContext import org.jetbrains.kotlin.serialization.deserialization.DeserializationContext
import org.jetbrains.kotlin.storage.getValue import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.addIfNotNull
import org.jetbrains.kotlin.utils.compactIfPossible import org.jetbrains.kotlin.utils.compactIfPossible
import java.util.* import java.util.*
@@ -68,7 +69,7 @@ abstract class DeserializedMemberScope protected constructor(
propertyProtos.keys + getNonDeclaredVariableNames() propertyProtos.keys + getNonDeclaredVariableNames()
} }
protected val typeAliasNames: Set<Name> get() = typeAliasProtos.keys private val typeAliasNames: Set<Name> get() = typeAliasProtos.keys
override fun getFunctionNames() = functionNamesLazy override fun getFunctionNames() = functionNamesLazy
override fun getVariableNames() = variableNamesLazy override fun getVariableNames() = variableNamesLazy
@@ -154,6 +155,14 @@ abstract class DeserializedMemberScope protected constructor(
addClassifierDescriptors(result, nameFilter) addClassifierDescriptors(result, nameFilter)
} }
if (kindFilter.acceptsKinds(DescriptorKindFilter.TYPE_ALIASES_MASK)) {
for (typeAliasName in typeAliasNames) {
if (nameFilter(typeAliasName)) {
result.addIfNotNull(getTypeAlias(typeAliasName))
}
}
}
return result.compactIfPossible() return result.compactIfPossible()
} }
@@ -65,11 +65,6 @@ open class DeserializedPackageMemberScope(
result.addIfNotNull(getClassDescriptor(className)) result.addIfNotNull(getClassDescriptor(className))
} }
} }
for (typeAliasName in typeAliasNames) {
if (nameFilter(typeAliasName)) {
result.addIfNotNull(getTypeAlias(typeAliasName))
}
}
} }
override fun getNonDeclaredFunctionNames(): Set<Name> = emptySet() override fun getNonDeclaredFunctionNames(): Set<Name> = emptySet()