Refactoring. Move flexible type factory to deserialization module.
This commit is contained in:
+11
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
||||
import org.jetbrains.kotlin.load.kotlin.JavaFlexibleTypeDeserializer;
|
||||
import org.jetbrains.kotlin.name.ClassId;
|
||||
import org.jetbrains.kotlin.serialization.AnnotationSerializer;
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf;
|
||||
@@ -31,6 +32,7 @@ import org.jetbrains.kotlin.serialization.SerializerExtension;
|
||||
import org.jetbrains.kotlin.serialization.StringTable;
|
||||
import org.jetbrains.kotlin.serialization.jvm.ClassMapperLite;
|
||||
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf;
|
||||
import org.jetbrains.kotlin.types.DelegatingFlexibleType;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.RawTypeCapability;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
@@ -80,6 +82,15 @@ public class JvmSerializerExtension extends SerializerExtension {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeFlexibleType(
|
||||
@NotNull DelegatingFlexibleType flexibleType,
|
||||
@NotNull ProtoBuf.Type.Builder lowerProto,
|
||||
@NotNull ProtoBuf.Type.Builder upperProto
|
||||
) {
|
||||
lowerProto.setFlexibleTypeCapabilitiesId(getStringTable().getStringIndex(JavaFlexibleTypeDeserializer.INSTANCE.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeType(@NotNull KotlinType type, @NotNull ProtoBuf.Type.Builder proto) {
|
||||
// TODO: don't store type annotations in our binary metadata on Java 8, use *TypeAnnotations attributes instead
|
||||
|
||||
+6
-5
@@ -506,15 +506,16 @@ public class DescriptorSerializer {
|
||||
}
|
||||
|
||||
if (FlexibleTypesKt.isFlexible(type)) {
|
||||
Flexibility flexibility = FlexibleTypesKt.flexibility(type);
|
||||
DelegatingFlexibleType flexibleType = (DelegatingFlexibleType) FlexibleTypesKt.flexibility(type);
|
||||
|
||||
ProtoBuf.Type.Builder lowerBound = type(flexibility.getLowerBound());
|
||||
lowerBound.setFlexibleTypeCapabilitiesId(getStringTable().getStringIndex(flexibility.getFactory().getId()));
|
||||
ProtoBuf.Type.Builder lowerBound = type(flexibleType.getLowerBound());
|
||||
ProtoBuf.Type.Builder upperBound = type(flexibleType.getUpperBound());
|
||||
extension.serializeFlexibleType(flexibleType, lowerBound, upperBound);
|
||||
if (useTypeTable()) {
|
||||
lowerBound.setFlexibleUpperBoundId(typeId(flexibility.getUpperBound()));
|
||||
lowerBound.setFlexibleUpperBoundId(typeTable.get(upperBound));
|
||||
}
|
||||
else {
|
||||
lowerBound.setFlexibleUpperBound(type(flexibility.getUpperBound()));
|
||||
lowerBound.setFlexibleUpperBound(upperBound);
|
||||
}
|
||||
return lowerBound;
|
||||
}
|
||||
|
||||
+6
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -18,6 +18,8 @@ package org.jetbrains.kotlin.serialization;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.types.DelegatingFlexibleType;
|
||||
import org.jetbrains.kotlin.types.Flexibility;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
public abstract class SerializerExtension {
|
||||
@@ -49,6 +51,9 @@ public abstract class SerializerExtension {
|
||||
public void serializeValueParameter(@NotNull ValueParameterDescriptor descriptor, @NotNull ProtoBuf.ValueParameter.Builder proto) {
|
||||
}
|
||||
|
||||
public void serializeFlexibleType(@NotNull DelegatingFlexibleType flexibleType, @NotNull ProtoBuf.Type.Builder lowerProto, @NotNull ProtoBuf.Type.Builder upperProto) {
|
||||
}
|
||||
|
||||
public void serializeType(@NotNull KotlinType type, @NotNull ProtoBuf.Type.Builder proto) {
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.load.java.lazy.LazyJavaPackageFragmentProvider
|
||||
import org.jetbrains.kotlin.serialization.deserialization.*
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.FlexibleJavaClassifierTypeFactory
|
||||
|
||||
// This class is needed only for easier injection: exact types of needed components are specified in the constructor here.
|
||||
// Otherwise injector generator is not smart enough to deduce, for example, which package fragment provider DeserializationComponents needs
|
||||
@@ -42,7 +41,7 @@ class DeserializationComponentsForJava(
|
||||
val settings = JvmBuiltInsSettings(moduleDescriptor, storageManager, { moduleDescriptor })
|
||||
components = DeserializationComponents(
|
||||
storageManager, moduleDescriptor, classDataFinder, annotationAndConstantLoader, packageFragmentProvider, localClassResolver,
|
||||
errorReporter, lookupTracker, FlexibleJavaClassifierTypeFactory, ClassDescriptorFactory.EMPTY,
|
||||
errorReporter, lookupTracker, JavaFlexibleTypeDeserializer, ClassDescriptorFactory.EMPTY,
|
||||
notFoundClasses, JavaTypeCapabilitiesLoader,
|
||||
additionalClassPartsProvider = settings,
|
||||
platformDependentDeclarationFilter = settings
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.load.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.serialization.deserialization.FlexibleTypeDeserializer
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||
import org.jetbrains.kotlin.types.SimpleType
|
||||
|
||||
object JavaFlexibleTypeDeserializer : FlexibleTypeDeserializer {
|
||||
val id = "kotlin.jvm.PlatformType"
|
||||
|
||||
override fun create(flexibleId: String, lowerBound: SimpleType, upperBound: SimpleType): KotlinType {
|
||||
if (flexibleId != id) return ErrorUtils.createErrorType("Error java flexible type with id: $flexibleId. ($lowerBound..$upperBound)")
|
||||
return KotlinTypeFactory.flexibleType(lowerBound, upperBound)
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.serialization.deserialization.*
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.FlexibleTypeFactory
|
||||
import java.io.InputStream
|
||||
|
||||
fun createBuiltInPackageFragmentProvider(
|
||||
@@ -52,7 +51,7 @@ fun createBuiltInPackageFragmentProvider(
|
||||
localClassResolver,
|
||||
ErrorReporter.DO_NOTHING,
|
||||
LookupTracker.DO_NOTHING,
|
||||
FlexibleTypeFactory.ThrowException,
|
||||
FlexibleTypeDeserializer.ThrowException,
|
||||
classDescriptorFactory,
|
||||
notFoundClasses,
|
||||
additionalClassPartsProvider = additionalClassPartsProvider,
|
||||
|
||||
@@ -31,11 +31,11 @@ class DynamicTypesAllowed: DynamicTypesSettings() {
|
||||
get() = true
|
||||
}
|
||||
|
||||
fun KotlinType.isDynamic(): Boolean = this.getCapability(Flexibility::class.java)?.factory == DynamicTypeFactory
|
||||
fun KotlinType.isDynamic(): Boolean = unwrap() is DynamicType
|
||||
|
||||
fun createDynamicType(builtIns: KotlinBuiltIns) = DynamicType(builtIns, Annotations.EMPTY)
|
||||
|
||||
class DynamicType(builtIns: KotlinBuiltIns, override val annotations: Annotations) : DelegatingFlexibleType(builtIns.nothingType, builtIns.nullableAnyType, DynamicTypeFactory) {
|
||||
class DynamicType(builtIns: KotlinBuiltIns, override val annotations: Annotations) : DelegatingFlexibleType(builtIns.nothingType, builtIns.nullableAnyType) {
|
||||
override val delegateType: KotlinType get() = upperBound
|
||||
|
||||
override fun makeNullableAsSpecified(nullable: Boolean): KotlinType {
|
||||
@@ -47,18 +47,3 @@ class DynamicType(builtIns: KotlinBuiltIns, override val annotations: Annotation
|
||||
|
||||
override fun replaceAnnotations(newAnnotations: Annotations): KotlinType = DynamicType(delegateType.builtIns, annotations)
|
||||
}
|
||||
|
||||
object DynamicTypeFactory : FlexibleTypeFactory {
|
||||
override fun create(lowerBound: SimpleType, upperBound: SimpleType): KotlinType {
|
||||
if (KotlinTypeChecker.FLEXIBLE_UNEQUAL_TO_INFLEXIBLE.equalTypes(lowerBound, lowerBound.builtIns.nothingType) &&
|
||||
KotlinTypeChecker.FLEXIBLE_UNEQUAL_TO_INFLEXIBLE.equalTypes(upperBound, upperBound.builtIns.nullableAnyType)) {
|
||||
return createDynamicType(lowerBound.builtIns)
|
||||
}
|
||||
else {
|
||||
throw IllegalStateException("Illegal type range for dynamic type: $lowerBound..$upperBound")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override val id: String get() = "kotlin.DynamicType"
|
||||
}
|
||||
|
||||
@@ -21,27 +21,11 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations
|
||||
|
||||
interface FlexibleTypeFactory {
|
||||
val id: String
|
||||
|
||||
fun create(lowerBound: SimpleType, upperBound: SimpleType): KotlinType
|
||||
|
||||
object ThrowException : FlexibleTypeFactory {
|
||||
private fun error(): Nothing = throw IllegalArgumentException("This factory should not be used.")
|
||||
override val id: String
|
||||
get() = error()
|
||||
|
||||
override fun create(lowerBound: SimpleType, upperBound: SimpleType): KotlinType = error()
|
||||
}
|
||||
}
|
||||
|
||||
interface Flexibility : TypeCapability, SubtypingRepresentatives {
|
||||
// lowerBound is a subtype of upperBound
|
||||
val lowerBound: SimpleType
|
||||
val upperBound: SimpleType
|
||||
|
||||
val factory: FlexibleTypeFactory
|
||||
|
||||
override val subTypeRepresentative: KotlinType
|
||||
get() = lowerBound
|
||||
|
||||
@@ -102,8 +86,7 @@ fun KotlinType.upperIfFlexible(): SimpleType = (if (this.isFlexible()) this.flex
|
||||
|
||||
abstract class DelegatingFlexibleType protected constructor(
|
||||
override val lowerBound: SimpleType,
|
||||
override val upperBound: SimpleType,
|
||||
override val factory: FlexibleTypeFactory
|
||||
override val upperBound: SimpleType
|
||||
) : DelegatingType(), Flexibility {
|
||||
companion object {
|
||||
@JvmField
|
||||
@@ -152,8 +135,7 @@ abstract class DelegatingFlexibleType protected constructor(
|
||||
override fun toString() = "('$lowerBound'..'$upperBound')"
|
||||
}
|
||||
|
||||
class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) :
|
||||
DelegatingFlexibleType(lowerBound, upperBound, FlexibleJavaClassifierTypeFactory), CustomTypeVariable {
|
||||
class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : DelegatingFlexibleType(lowerBound, upperBound), CustomTypeVariable {
|
||||
|
||||
override val delegateType: KotlinType get() = lowerBound
|
||||
|
||||
@@ -180,11 +162,3 @@ class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) :
|
||||
override fun replaceAnnotations(newAnnotations: Annotations): KotlinType
|
||||
= KotlinTypeFactory.flexibleType(lowerBound.replaceAnnotations(newAnnotations).asSimpleType(), upperBound)
|
||||
}
|
||||
|
||||
// TODO: move Factory to descriptor.loader.java
|
||||
object FlexibleJavaClassifierTypeFactory : FlexibleTypeFactory {
|
||||
override fun create(lowerBound: SimpleType, upperBound: SimpleType): KotlinType
|
||||
= KotlinTypeFactory.flexibleType(lowerBound, upperBound)
|
||||
|
||||
override val id: String get() = "kotlin.jvm.PlatformType"
|
||||
}
|
||||
|
||||
+30
@@ -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()
|
||||
}
|
||||
}
|
||||
+1
-7
@@ -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)
|
||||
|
||||
+1
-3
@@ -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,
|
||||
|
||||
+1
-2
@@ -32,7 +32,6 @@ import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.serialization.builtins.BuiltInsProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.*
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPackageMemberScope
|
||||
import org.jetbrains.kotlin.types.FlexibleTypeFactory
|
||||
|
||||
class KotlinBuiltInDeserializerForDecompiler(
|
||||
packageDirectory: VirtualFile,
|
||||
@@ -52,7 +51,7 @@ class KotlinBuiltInDeserializerForDecompiler(
|
||||
storageManager, moduleDescriptor, BuiltInsClassDataFinder(proto, nameResolver),
|
||||
AnnotationAndConstantLoaderImpl(moduleDescriptor, notFoundClasses, BuiltInSerializerProtocol), packageFragmentProvider,
|
||||
ResolveEverythingToKotlinAnyLocalClassifierResolver(builtIns), LoggingErrorReporter(LOG),
|
||||
LookupTracker.DO_NOTHING, FlexibleTypeFactory.ThrowException, ClassDescriptorFactory.EMPTY,
|
||||
LookupTracker.DO_NOTHING, FlexibleTypeDeserializer.ThrowException, ClassDescriptorFactory.EMPTY,
|
||||
notFoundClasses
|
||||
)
|
||||
}
|
||||
|
||||
+1
-2
@@ -39,7 +39,6 @@ import org.jetbrains.kotlin.serialization.deserialization.DeserializationCompone
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NotFoundClasses
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPackageMemberScope
|
||||
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBufUtil
|
||||
import org.jetbrains.kotlin.types.FlexibleJavaClassifierTypeFactory
|
||||
|
||||
fun DeserializerForClassfileDecompiler(classFile: VirtualFile): DeserializerForClassfileDecompiler {
|
||||
val kotlinClassHeaderInfo = IDEKotlinBinaryClassCache.getKotlinBinaryClassHeaderData(classFile)
|
||||
@@ -68,7 +67,7 @@ class DeserializerForClassfileDecompiler(
|
||||
deserializationComponents = DeserializationComponents(
|
||||
storageManager, moduleDescriptor, classDataFinder, annotationAndConstantLoader, packageFragmentProvider,
|
||||
ResolveEverythingToKotlinAnyLocalClassifierResolver(builtIns), LoggingErrorReporter(LOG),
|
||||
LookupTracker.DO_NOTHING, FlexibleJavaClassifierTypeFactory, ClassDescriptorFactory.EMPTY, notFoundClasses
|
||||
LookupTracker.DO_NOTHING, JavaFlexibleTypeDeserializer, ClassDescriptorFactory.EMPTY, notFoundClasses
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -31,10 +31,10 @@ import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.*
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPackageMemberScope
|
||||
import org.jetbrains.kotlin.serialization.js.DynamicTypeDeserializer
|
||||
import org.jetbrains.kotlin.serialization.js.JsSerializerProtocol
|
||||
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptClassDataFinder
|
||||
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializedResourcePaths
|
||||
import org.jetbrains.kotlin.types.DynamicTypeFactory
|
||||
import java.io.ByteArrayInputStream
|
||||
|
||||
class KotlinJavaScriptDeserializerForDecompiler(
|
||||
@@ -65,7 +65,7 @@ class KotlinJavaScriptDeserializerForDecompiler(
|
||||
deserializationComponents = DeserializationComponents(
|
||||
storageManager, moduleDescriptor, classDataFinder, annotationAndConstantLoader, packageFragmentProvider,
|
||||
ResolveEverythingToKotlinAnyLocalClassifierResolver(builtIns), LoggingErrorReporter(LOG),
|
||||
LookupTracker.DO_NOTHING, DynamicTypeFactory, ClassDescriptorFactory.EMPTY,
|
||||
LookupTracker.DO_NOTHING, DynamicTypeDeserializer, ClassDescriptorFactory.EMPTY,
|
||||
notFoundClasses
|
||||
)
|
||||
}
|
||||
|
||||
+2
-2
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.serialization.ProtoBuf.Type
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf.Type.Argument.Projection
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf.TypeParameter.Variance
|
||||
import org.jetbrains.kotlin.serialization.deserialization.*
|
||||
import org.jetbrains.kotlin.types.DynamicTypeFactory
|
||||
import org.jetbrains.kotlin.serialization.js.DynamicTypeDeserializer
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||
import java.util.*
|
||||
|
||||
@@ -71,7 +71,7 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
if (type.hasFlexibleTypeCapabilitiesId()) {
|
||||
val id = c.nameResolver.getString(type.flexibleTypeCapabilitiesId)
|
||||
|
||||
if (id == DynamicTypeFactory.id) {
|
||||
if (id == DynamicTypeDeserializer.id) {
|
||||
KotlinPlaceHolderStubImpl<KtDynamicType>(parent, KtStubElementTypes.DYNAMIC_TYPE)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.js
|
||||
|
||||
import org.jetbrains.kotlin.serialization.deserialization.FlexibleTypeDeserializer
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.SimpleType
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.createDynamicType
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
|
||||
object DynamicTypeDeserializer : FlexibleTypeDeserializer {
|
||||
val id = "kotlin.DynamicType"
|
||||
|
||||
override fun create(flexibleId: String, lowerBound: SimpleType, upperBound: SimpleType): KotlinType {
|
||||
if (flexibleId != id) return ErrorUtils.createErrorType("Unexpected id: $flexibleId. ($lowerBound..$upperBound)")
|
||||
if (KotlinTypeChecker.FLEXIBLE_UNEQUAL_TO_INFLEXIBLE.equalTypes(lowerBound, lowerBound.builtIns.nothingType) &&
|
||||
KotlinTypeChecker.FLEXIBLE_UNEQUAL_TO_INFLEXIBLE.equalTypes(upperBound, upperBound.builtIns.nullableAnyType)) {
|
||||
return createDynamicType(lowerBound.builtIns)
|
||||
}
|
||||
else {
|
||||
return ErrorUtils.createErrorType("Illegal type range for dynamic type: $lowerBound..$upperBound")
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -18,9 +18,15 @@ package org.jetbrains.kotlin.serialization.js
|
||||
|
||||
import com.google.protobuf.ExtensionRegistryLite
|
||||
import org.jetbrains.kotlin.serialization.KotlinSerializerExtensionBase
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.SerializerExtensionProtocol
|
||||
import org.jetbrains.kotlin.types.DelegatingFlexibleType
|
||||
|
||||
class KotlinJavascriptSerializerExtension : KotlinSerializerExtensionBase(JsSerializerProtocol)
|
||||
class KotlinJavascriptSerializerExtension : KotlinSerializerExtensionBase(JsSerializerProtocol) {
|
||||
override fun serializeFlexibleType(flexibleType: DelegatingFlexibleType, lowerProto: ProtoBuf.Type.Builder, upperProto: ProtoBuf.Type.Builder) {
|
||||
lowerProto.flexibleTypeCapabilitiesId = stringTable.getStringIndex(DynamicTypeDeserializer.id)
|
||||
}
|
||||
}
|
||||
|
||||
object JsSerializerProtocol : SerializerExtensionProtocol(
|
||||
ExtensionRegistryLite.newInstance().apply { JsProtoBuf.registerAllExtensions(this) },
|
||||
|
||||
+1
-2
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.serialization.deserialization.*
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.DynamicTypeFactory
|
||||
import java.io.InputStream
|
||||
|
||||
fun createKotlinJavascriptPackageFragmentProvider(
|
||||
@@ -49,7 +48,7 @@ fun createKotlinJavascriptPackageFragmentProvider(
|
||||
localClassResolver,
|
||||
ErrorReporter.DO_NOTHING,
|
||||
LookupTracker.DO_NOTHING,
|
||||
DynamicTypeFactory,
|
||||
DynamicTypeDeserializer,
|
||||
ClassDescriptorFactory.EMPTY,
|
||||
notFoundClasses
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user