Remake KotlinTypes.

This commit is contained in:
Stanislav Erokhin
2016-06-03 18:45:41 +03:00
parent 56122460aa
commit 1d9ca06b96
40 changed files with 283 additions and 523 deletions
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.utils.toReadOnlyList
class DeserializedType(
class DeserializedType private constructor(
private val c: DeserializationContext,
private val typeProto: ProtoBuf.Type,
private val additionalAnnotations: Annotations = Annotations.EMPTY
@@ -54,9 +54,18 @@ class DeserializedType(
return descriptor != null && ErrorUtils.isError(descriptor)
}
override val abbreviatedType by c.storageManager.createNullableLazyValue {
val abbreviatedTypeProto = typeProto.abbreviatedType(c.typeTable) ?: return@createNullableLazyValue null
companion object {
fun create(
c: DeserializationContext,
typeProto: ProtoBuf.Type,
additionalAnnotations: Annotations
): SimpleType {
val deserializedType = DeserializedType(c, typeProto, additionalAnnotations)
val abbreviatedTypeProto = typeProto.abbreviatedType(c.typeTable) ?: return deserializedType
c.typeDeserializer.type(abbreviatedTypeProto, additionalAnnotations).asSimpleType()
return deserializedType.withAbbreviatedType(DeserializedType(c, abbreviatedTypeProto, additionalAnnotations))
}
}
}
@@ -58,12 +58,12 @@ class TypeDeserializer(
fun type(proto: ProtoBuf.Type, additionalAnnotations: Annotations = Annotations.EMPTY): KotlinType {
if (proto.hasFlexibleTypeCapabilitiesId()) {
val id = c.nameResolver.getString(proto.flexibleTypeCapabilitiesId)
val lowerBound = DeserializedType(c, proto, additionalAnnotations)
val upperBound = DeserializedType(c, proto.flexibleUpperBound(c.typeTable)!!, additionalAnnotations)
val lowerBound = DeserializedType.create(c, proto, additionalAnnotations)
val upperBound = DeserializedType.create(c, proto.flexibleUpperBound(c.typeTable)!!, additionalAnnotations)
return c.components.flexibleTypeDeserializer.create(proto, id, lowerBound, upperBound)
}
return DeserializedType(c, proto, additionalAnnotations)
return DeserializedType.create(c, proto, additionalAnnotations)
}
fun typeConstructor(proto: ProtoBuf.Type): TypeConstructor =