Remake Raw type representation.

(cherry picked from commit b21cede)
This commit is contained in:
Stanislav Erokhin
2016-05-31 16:22:33 +03:00
parent 04e97f5058
commit 203c4cd94d
42 changed files with 277 additions and 354 deletions
@@ -56,15 +56,9 @@ class DeserializedType(
override val capabilities: TypeCapabilities get() = typeCapabilities()
private val typeCapabilities = c.storageManager.createLazyValue {
val deserializedCapabilities = c.components.typeCapabilitiesLoader.loadCapabilities(typeProto)
val abbreviatedTypeProto = typeProto.abbreviatedType(c.typeTable) ?: return@createLazyValue TypeCapabilities.NONE
val abbreviatedTypeProto = typeProto.abbreviatedType(c.typeTable)
if (abbreviatedTypeProto == null) {
deserializedCapabilities
}
else {
val abbreviatedType = c.typeDeserializer.type(abbreviatedTypeProto, additionalAnnotations)
deserializedCapabilities.withAbbreviatedType(abbreviatedType)
}
val abbreviatedType = c.typeDeserializer.type(abbreviatedTypeProto, additionalAnnotations)
TypeCapabilities.NONE.withAbbreviatedType(abbreviatedType)
}
}
@@ -16,15 +16,16 @@
package org.jetbrains.kotlin.serialization.deserialization
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.SimpleType
interface FlexibleTypeDeserializer {
fun create(flexibleId: String, lowerBound: SimpleType, upperBound: SimpleType): KotlinType
fun create(proto: ProtoBuf.Type, flexibleId: String, lowerBound: SimpleType, upperBound: SimpleType): KotlinType
object ThrowException : FlexibleTypeDeserializer {
private fun error(): Nothing = throw IllegalArgumentException("This factory should not be used.")
override fun create(flexibleId: String, lowerBound: SimpleType, upperBound: SimpleType): KotlinType = error()
override fun create(proto: ProtoBuf.Type, flexibleId: String, lowerBound: SimpleType, upperBound: SimpleType): KotlinType = error()
}
}
@@ -1,28 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.serialization.deserialization
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.types.TypeCapabilities
abstract class TypeCapabilitiesLoader {
object NONE : TypeCapabilitiesLoader() {
override fun loadCapabilities(type: ProtoBuf.Type): TypeCapabilities = TypeCapabilities.NONE
}
abstract fun loadCapabilities(type: ProtoBuf.Type): TypeCapabilities
}
@@ -58,7 +58,9 @@ class TypeDeserializer(
fun type(proto: ProtoBuf.Type, additionalAnnotations: Annotations = Annotations.EMPTY): KotlinType {
if (proto.hasFlexibleTypeCapabilitiesId()) {
val id = c.nameResolver.getString(proto.flexibleTypeCapabilitiesId)
return c.components.flexibleTypeDeserializer.create(id, DeserializedType(c, proto), DeserializedType(c, proto.flexibleUpperBound(c.typeTable)!!))
val lowerBound = DeserializedType(c, proto, additionalAnnotations)
val upperBound = DeserializedType(c, proto.flexibleUpperBound(c.typeTable)!!, additionalAnnotations)
return c.components.flexibleTypeDeserializer.create(proto, id, lowerBound, upperBound)
}
return DeserializedType(c, proto, additionalAnnotations)
@@ -37,7 +37,6 @@ class DeserializationComponents(
val flexibleTypeDeserializer: FlexibleTypeDeserializer,
val fictitiousClassDescriptorFactory: ClassDescriptorFactory,
val notFoundClasses: NotFoundClasses,
val typeCapabilitiesLoader: TypeCapabilitiesLoader = TypeCapabilitiesLoader.NONE,
val additionalClassPartsProvider: AdditionalClassPartsProvider = AdditionalClassPartsProvider.None,
val platformDependentDeclarationFilter: PlatformDependentDeclarationFilter = PlatformDependentDeclarationFilter.All
) {