Refactoring. Move flexible type factory to deserialization module.

This commit is contained in:
Stanislav Erokhin
2016-05-25 17:57:37 +03:00
parent 42857992ed
commit 669558c4ba
18 changed files with 148 additions and 77 deletions
@@ -0,0 +1,30 @@
/*
* Copyright 2010-2016 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.types.KotlinType
import org.jetbrains.kotlin.types.SimpleType
interface FlexibleTypeDeserializer {
fun create(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()
}
}
@@ -58,13 +58,7 @@ class TypeDeserializer(
fun type(proto: ProtoBuf.Type, additionalAnnotations: Annotations = Annotations.EMPTY): KotlinType {
if (proto.hasFlexibleTypeCapabilitiesId()) {
val id = c.nameResolver.getString(proto.flexibleTypeCapabilitiesId)
val flexibleTypeFactory = c.components.flexibleTypeFactory
if (flexibleTypeFactory.id != id) {
return ErrorUtils.createErrorType("${DeserializedType(c, proto)}: " +
"Unexpected flexible type factory. Expected: ${flexibleTypeFactory.id} Actual: $id")
}
return flexibleTypeFactory.create(DeserializedType(c, proto), DeserializedType(c, proto.flexibleUpperBound(c.typeTable)!!))
return c.components.flexibleTypeDeserializer.create(id, DeserializedType(c, proto), DeserializedType(c, proto.flexibleUpperBound(c.typeTable)!!))
}
return DeserializedType(c, proto, additionalAnnotations)
@@ -23,9 +23,7 @@ import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.resolve.constants.ConstantValue
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.TypeAliasDeserializer
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.FlexibleTypeFactory
class DeserializationComponents(
val storageManager: StorageManager,
@@ -36,7 +34,7 @@ class DeserializationComponents(
val localClassifierResolver: LocalClassifierResolver,
val errorReporter: ErrorReporter,
val lookupTracker: LookupTracker,
val flexibleTypeFactory: FlexibleTypeFactory,
val flexibleTypeDeserializer: FlexibleTypeDeserializer,
val fictitiousClassDescriptorFactory: ClassDescriptorFactory,
val notFoundClasses: NotFoundClasses,
val typeCapabilitiesLoader: TypeCapabilitiesLoader = TypeCapabilitiesLoader.NONE,