diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/serialization/JvmSerializerExtension.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/serialization/JvmSerializerExtension.java index aebc29d358c..f9691b3bf8d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/serialization/JvmSerializerExtension.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/serialization/JvmSerializerExtension.java @@ -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 diff --git a/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java b/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java index e3efb39564d..58e89d3e289 100644 --- a/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java +++ b/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java @@ -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; } diff --git a/compiler/serialization/src/org/jetbrains/kotlin/serialization/SerializerExtension.java b/compiler/serialization/src/org/jetbrains/kotlin/serialization/SerializerExtension.java index 784864bf945..04e56be4c97 100644 --- a/compiler/serialization/src/org/jetbrains/kotlin/serialization/SerializerExtension.java +++ b/compiler/serialization/src/org/jetbrains/kotlin/serialization/SerializerExtension.java @@ -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) { } diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/DeserializationComponentsForJava.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/DeserializationComponentsForJava.kt index dcda3223632..dedbe369bca 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/DeserializationComponentsForJava.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/DeserializationComponentsForJava.kt @@ -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 diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/JavaFlexibleTypeDeserializer.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/JavaFlexibleTypeDeserializer.kt new file mode 100644 index 00000000000..4e8ce70e898 --- /dev/null +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/JavaFlexibleTypeDeserializer.kt @@ -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) + } +} \ No newline at end of file diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/builtInsPackageFragmentProvider.kt b/core/descriptors/src/org/jetbrains/kotlin/builtins/builtInsPackageFragmentProvider.kt index d1612ef85fb..7abf79e39bf 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/builtInsPackageFragmentProvider.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/builtInsPackageFragmentProvider.kt @@ -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, diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/dynamicTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/types/dynamicTypes.kt index bce2f3c7cfc..b0e3983b089 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/dynamicTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/dynamicTypes.kt @@ -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" -} diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt index 9e63b491382..9199164db26 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt @@ -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" -} diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/FlexibleTypeDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/FlexibleTypeDeserializer.kt new file mode 100644 index 00000000000..99248aadfaa --- /dev/null +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/FlexibleTypeDeserializer.kt @@ -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() + } +} diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt index 87875ee820f..215a272b6b2 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt @@ -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) diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/context.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/context.kt index 7758a9f4af4..fa144b4cf07 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/context.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/context.kt @@ -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, diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/builtIns/KotlinBuiltInDeserializerForDecompiler.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/builtIns/KotlinBuiltInDeserializerForDecompiler.kt index 4132cded4b9..50fff66fba9 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/builtIns/KotlinBuiltInDeserializerForDecompiler.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/builtIns/KotlinBuiltInDeserializerForDecompiler.kt @@ -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 ) } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/DeserializerForClassfileDecompiler.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/DeserializerForClassfileDecompiler.kt index 2d2ec5a46a8..77a8ccd2560 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/DeserializerForClassfileDecompiler.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/DeserializerForClassfileDecompiler.kt @@ -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 ) } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/js/KotlinJavaScriptDeserializerForDecompiler.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/js/KotlinJavaScriptDeserializerForDecompiler.kt index 60af2f837fc..06e918e906c 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/js/KotlinJavaScriptDeserializerForDecompiler.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/js/KotlinJavaScriptDeserializerForDecompiler.kt @@ -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 ) } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt index fa195205b93..2bba620f249 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt @@ -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(parent, KtStubElementTypes.DYNAMIC_TYPE) return } diff --git a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/DynamicTypeDeserializer.kt b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/DynamicTypeDeserializer.kt new file mode 100644 index 00000000000..052961f68cb --- /dev/null +++ b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/DynamicTypeDeserializer.kt @@ -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") + } + } +} \ No newline at end of file diff --git a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptSerializerExtension.kt b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptSerializerExtension.kt index 161c42551f4..dcf865b2788 100644 --- a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptSerializerExtension.kt +++ b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptSerializerExtension.kt @@ -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) }, diff --git a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/kotlinJavascriptPackageFragmentProvider.kt b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/kotlinJavascriptPackageFragmentProvider.kt index 5c6a0681382..6b08995213a 100644 --- a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/kotlinJavascriptPackageFragmentProvider.kt +++ b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/kotlinJavascriptPackageFragmentProvider.kt @@ -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 )