Implement raw types (de)serialization via special TypeCapabilities
This commit is contained in:
+3
-1
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.types.LazyType
|
||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||
|
||||
class DeserializedType(
|
||||
c: DeserializationContext,
|
||||
private val c: DeserializationContext,
|
||||
private val typeProto: ProtoBuf.Type
|
||||
) : AbstractLazyType(c.storageManager), LazyType {
|
||||
private val typeDeserializer = c.typeDeserializer
|
||||
@@ -51,6 +51,8 @@ class DeserializedType(
|
||||
|
||||
override fun getAnnotations(): Annotations = annotations
|
||||
|
||||
override fun getCapabilities() = c.components.typeCapabilitiesLoader.loadCapabilities(typeProto)
|
||||
|
||||
private fun <E: Any> List<E>.getOrNull(index: Int): E? {
|
||||
return if (index in indices) this[index] else null
|
||||
}
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
public abstract class TypeCapabilitiesLoader {
|
||||
public object NONE : TypeCapabilitiesLoader() {
|
||||
override fun loadCapabilities(type: ProtoBuf.Type): TypeCapabilities = TypeCapabilities.NONE
|
||||
}
|
||||
|
||||
public abstract fun loadCapabilities(type: ProtoBuf.Type): TypeCapabilities
|
||||
}
|
||||
+2
-1
@@ -31,7 +31,8 @@ public class DeserializationComponents(
|
||||
public val packageFragmentProvider: PackageFragmentProvider,
|
||||
public val localClassResolver: LocalClassResolver,
|
||||
public val flexibleTypeCapabilitiesDeserializer: FlexibleTypeCapabilitiesDeserializer,
|
||||
public val fictitiousClassDescriptorFactory: ClassDescriptorFactory
|
||||
public val fictitiousClassDescriptorFactory: ClassDescriptorFactory,
|
||||
public val typeCapabilitiesLoader: TypeCapabilitiesLoader = TypeCapabilitiesLoader.NONE
|
||||
) {
|
||||
public val classDeserializer: ClassDeserializer = ClassDeserializer(this)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user