diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PossiblyBareType.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PossiblyBareType.java index b3eeee21984..db162e41e60 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PossiblyBareType.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PossiblyBareType.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. @@ -94,12 +94,12 @@ public class PossiblyBareType { KotlinType nullableActualType = TypeUtils.makeNullable(getActualType()); - KotlinType abbreviatedType = TypeCapabilitiesKt.getAbbreviatedType(getActualType()); + KotlinType abbreviatedType = KotlinTypeKt.getAbbreviatedType(getActualType()); if (abbreviatedType == null) { return type(nullableActualType); } else { - return type(TypeCapabilitiesKt.withAbbreviatedType(nullableActualType, TypeUtils.makeNullable(abbreviatedType))); + return type(KotlinTypeKt.withAbbreviatedType(KotlinTypeKt.asSimpleType(nullableActualType), KotlinTypeKt.asSimpleType(TypeUtils.makeNullable(abbreviatedType)))); } } diff --git a/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java b/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java index 5518a2ac204..4d71bcb0690 100644 --- a/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java +++ b/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java @@ -548,7 +548,7 @@ public class DescriptorSerializer { builder.setNullable(type.isMarkedNullable()); } - KotlinType abbreviatedType = TypeCapabilitiesKt.getAbbreviatedType(type); + KotlinType abbreviatedType = KotlinTypeKt.getAbbreviatedType(type); if (abbreviatedType != null) { if (useTypeTable()) { builder.setAbbreviatedTypeId(typeId(abbreviatedType)); diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/AbstractKotlinType.java b/core/descriptors/src/org/jetbrains/kotlin/types/AbstractKotlinType.java index 8b44ec9d0a0..32c976a6ae8 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/AbstractKotlinType.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/AbstractKotlinType.java @@ -87,4 +87,10 @@ public abstract class AbstractKotlinType implements KotlinType, SimpleType { // return sb.toString(); } + + @Nullable + @Override + public SimpleType getAbbreviatedType() { + return null; + } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/DelegatingType.java b/core/descriptors/src/org/jetbrains/kotlin/types/DelegatingType.java index ee61878675f..de94c2e70af 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/DelegatingType.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/DelegatingType.java @@ -91,4 +91,10 @@ public abstract class DelegatingType implements KotlinType, SimpleType { // TODO public String toString() { return getDelegate().toString(); } + + @Nullable + @Override + public SimpleType getAbbreviatedType() { + return null; + } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java index 0c8e18ced95..4773a94f756 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java @@ -553,6 +553,12 @@ public class ErrorUtils { public String toString() { return constructor.toString() + (arguments.isEmpty() ? "" : joinToString(arguments, ", ", "<", ">", -1, "...", null)); } + + @Nullable + @Override + public SimpleType getAbbreviatedType() { + return null; + } } @NotNull diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt index 885f3966941..d805599915e 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt @@ -54,7 +54,9 @@ fun KotlinType.unwrap(): KotlinType { return this } -interface SimpleType : KotlinType +interface SimpleType : KotlinType { + val abbreviatedType : SimpleType? get() = null +} interface TypeWithCustomReplacement : KotlinType { fun makeNullableAsSpecified(nullable: Boolean): KotlinType @@ -111,6 +113,13 @@ fun SimpleType.lazyReplaceAnnotations(newAnnotations: Annotations): SimpleType { } } +fun KotlinType.getAbbreviatedType(): SimpleType? = (unwrap() as? SimpleType)?.abbreviatedType + +fun SimpleType.withAbbreviatedType(abbreviatedType: SimpleType): SimpleType { + if (isError) return this + return KotlinTypeImpl.create(annotations, constructor, isMarkedNullable, arguments, memberScope, capabilities, abbreviatedType) +} + private class WrappedSimpleType( override val delegate: SimpleType, val newAnnotations: Annotations? = null, @@ -124,7 +133,7 @@ private class WrappedSimpleType( override fun unwrap(): KotlinType { if (delegate.isError) return delegate // todo - return KotlinTypeImpl.create(annotations, constructor, isMarkedNullable, arguments, memberScope, capabilities) + return KotlinTypeImpl.create(annotations, constructor, isMarkedNullable, arguments, memberScope, capabilities, abbreviatedType) } override fun toString(): String { diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeImpl.kt index 183b5aa276c..f438d9d9665 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeImpl.kt @@ -21,7 +21,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.resolve.scopes.MemberScope open class KotlinTypeImpl -private constructor( +internal constructor( override val annotations: Annotations, final override val constructor: TypeConstructor, override val isMarkedNullable: Boolean, @@ -45,10 +45,11 @@ private constructor( nullable: Boolean, arguments: List, memberScope: MemberScope, - capabilities: TypeCapabilities + capabilities: TypeCapabilities, + abbreviatedType: SimpleType? = null ): KotlinTypeImpl { - if (capabilities !== TypeCapabilities.NONE) { - return WithCapabilities(annotations, constructor, nullable, arguments, memberScope, capabilities) + if (capabilities !== TypeCapabilities.NONE || abbreviatedType != null) { + return WithCapabilities(annotations, constructor, nullable, arguments, memberScope, capabilities, abbreviatedType) } return KotlinTypeImpl(annotations, constructor, nullable, arguments, memberScope) } @@ -70,7 +71,8 @@ private constructor( nullable: Boolean, arguments: List, memberScope: MemberScope, - override val capabilities: TypeCapabilities + override val capabilities: TypeCapabilities, + override val abbreviatedType: SimpleType? ) : KotlinTypeImpl(annotations, constructor, nullable, arguments, memberScope) init { diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeCapabilities.kt b/core/descriptors/src/org/jetbrains/kotlin/types/TypeCapabilities.kt index 90a2b80f9ac..b2ca5107a57 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeCapabilities.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeCapabilities.kt @@ -47,14 +47,6 @@ fun TypeCapabilities.addCapability(clazz: Class, typeCap return CompositeTypeCapabilities(this, newCapabilities) } -fun TypeCapabilities.overrideCapability(clazz: Class, typeCapability: T): TypeCapabilities { - if (getCapability(clazz) === typeCapability) return this - val newCapabilities = SingletonTypeCapabilities(clazz, typeCapability) - if (this === org.jetbrains.kotlin.types.TypeCapabilities.NONE) return newCapabilities - - return CompositeTypeCapabilities(newCapabilities, this) -} - inline fun KotlinType.getCapability(): T? = getCapability(T::class.java) @@ -92,20 +84,3 @@ fun sameTypeConstructors(first: KotlinType, second: KotlinType): Boolean { || (second.unwrap() as? SubtypingRepresentatives)?.sameTypeConstructor(first) ?: false } -interface AbbreviatedType : TypeCapability { - val abbreviatedType : KotlinType -} - -fun KotlinType.hasAbbreviatedType(): Boolean = - getCapability(AbbreviatedType::class.java) != null - -fun KotlinType.getAbbreviatedType(): KotlinType? = - getCapability(AbbreviatedType::class.java)?.abbreviatedType - -private class AbbreviatedTypeImpl(override val abbreviatedType: KotlinType): AbbreviatedType - -fun TypeCapabilities.withAbbreviatedType(abbreviatedType: KotlinType): TypeCapabilities = - overrideCapability(AbbreviatedType::class.java, AbbreviatedTypeImpl(abbreviatedType)) - -fun KotlinType.withAbbreviatedType(abbreviatedType: KotlinType): KotlinType = - if (!isError) replace(newCapabilities = capabilities.withAbbreviatedType(abbreviatedType)) else this diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java index 9172434902c..db22561bf5e 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java @@ -93,6 +93,12 @@ public class TypeUtils { public String toString() { return name; } + + @Nullable + @Override + public SimpleType getAbbreviatedType() { + return null; + } } @NotNull diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/DeserializedType.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/DeserializedType.kt index 7073609f4d2..7b24e017c6e 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/DeserializedType.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/DeserializedType.kt @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.serialization.ProtoBuf import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedAnnotationsWithPossibleTargets +import org.jetbrains.kotlin.storage.getValue import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.utils.toReadOnlyList @@ -53,12 +54,9 @@ class DeserializedType( return descriptor != null && ErrorUtils.isError(descriptor) } - override val capabilities: TypeCapabilities get() = typeCapabilities() + override val abbreviatedType by c.storageManager.createNullableLazyValue { + val abbreviatedTypeProto = typeProto.abbreviatedType(c.typeTable) ?: return@createNullableLazyValue null - private val typeCapabilities = c.storageManager.createLazyValue { - val abbreviatedTypeProto = typeProto.abbreviatedType(c.typeTable) ?: return@createLazyValue TypeCapabilities.NONE - - val abbreviatedType = c.typeDeserializer.type(abbreviatedTypeProto, additionalAnnotations) - TypeCapabilities.NONE.withAbbreviatedType(abbreviatedType) + c.typeDeserializer.type(abbreviatedTypeProto, additionalAnnotations).asSimpleType() } }