Minor, slightly refactor TypeDeserializer.typeConstructor
This commit is contained in:
+15
-13
@@ -38,9 +38,9 @@ class TypeDeserializer(
|
|||||||
computeTypeAliasDescriptor(fqNameIndex)
|
computeTypeAliasDescriptor(fqNameIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val typeParameterDescriptors =
|
private val typeParameterDescriptors: Map<Int, TypeParameterDescriptor> =
|
||||||
if (typeParameterProtos.isEmpty()) {
|
if (typeParameterProtos.isEmpty()) {
|
||||||
mapOf<Int, TypeParameterDescriptor>()
|
emptyMap()
|
||||||
} else {
|
} else {
|
||||||
val result = LinkedHashMap<Int, TypeParameterDescriptor>()
|
val result = LinkedHashMap<Int, TypeParameterDescriptor>()
|
||||||
for ((index, proto) in typeParameterProtos.withIndex()) {
|
for ((index, proto) in typeParameterProtos.withIndex()) {
|
||||||
@@ -133,22 +133,24 @@ class TypeDeserializer(
|
|||||||
return c.components.notFoundClasses.getClass(classId, typeParametersCount)
|
return c.components.notFoundClasses.getClass(classId, typeParametersCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
return when {
|
val classifier = when {
|
||||||
proto.hasClassName() -> (classifierDescriptors(proto.className) ?: notFoundClass(proto.className)).typeConstructor
|
proto.hasClassName() ->
|
||||||
|
classifierDescriptors(proto.className) ?: notFoundClass(proto.className)
|
||||||
proto.hasTypeParameter() ->
|
proto.hasTypeParameter() ->
|
||||||
typeParameterTypeConstructor(proto.typeParameter)
|
loadTypeParameter(proto.typeParameter)
|
||||||
?: ErrorUtils.createErrorTypeConstructor(
|
?: return ErrorUtils.createErrorTypeConstructor(
|
||||||
"Unknown type parameter ${proto.typeParameter}. Please try recompiling module containing \"$containerPresentableName\""
|
"Unknown type parameter ${proto.typeParameter}. Please try recompiling module containing \"$containerPresentableName\""
|
||||||
)
|
)
|
||||||
proto.hasTypeParameterName() -> {
|
proto.hasTypeParameterName() -> {
|
||||||
val container = c.containingDeclaration
|
|
||||||
val name = c.nameResolver.getString(proto.typeParameterName)
|
val name = c.nameResolver.getString(proto.typeParameterName)
|
||||||
val parameter = ownTypeParameters.find { it.name.asString() == name }
|
ownTypeParameters.find { it.name.asString() == name }
|
||||||
parameter?.typeConstructor ?: ErrorUtils.createErrorTypeConstructor("Deserialized type parameter $name in $container")
|
?: return ErrorUtils.createErrorTypeConstructor("Deserialized type parameter $name in ${c.containingDeclaration}")
|
||||||
}
|
}
|
||||||
proto.hasTypeAliasName() -> (typeAliasDescriptors(proto.typeAliasName) ?: notFoundClass(proto.typeAliasName)).typeConstructor
|
proto.hasTypeAliasName() ->
|
||||||
else -> ErrorUtils.createErrorTypeConstructor("Unknown type")
|
typeAliasDescriptors(proto.typeAliasName) ?: notFoundClass(proto.typeAliasName)
|
||||||
|
else -> return ErrorUtils.createErrorTypeConstructor("Unknown type")
|
||||||
}
|
}
|
||||||
|
return classifier.typeConstructor
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createSuspendFunctionType(
|
private fun createSuspendFunctionType(
|
||||||
@@ -233,8 +235,8 @@ class TypeDeserializer(
|
|||||||
).makeNullableAsSpecified(funType.isMarkedNullable)
|
).makeNullableAsSpecified(funType.isMarkedNullable)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun typeParameterTypeConstructor(typeParameterId: Int): TypeConstructor? =
|
private fun loadTypeParameter(typeParameterId: Int): TypeParameterDescriptor? =
|
||||||
typeParameterDescriptors[typeParameterId]?.typeConstructor ?: parent?.typeParameterTypeConstructor(typeParameterId)
|
typeParameterDescriptors[typeParameterId] ?: parent?.loadTypeParameter(typeParameterId)
|
||||||
|
|
||||||
private fun computeClassifierDescriptor(fqNameIndex: Int): ClassifierDescriptor? {
|
private fun computeClassifierDescriptor(fqNameIndex: Int): ClassifierDescriptor? {
|
||||||
val id = c.nameResolver.getClassId(fqNameIndex)
|
val id = c.nameResolver.getClassId(fqNameIndex)
|
||||||
|
|||||||
Reference in New Issue
Block a user