From 8992537180565f7c87ccb12e94d992129905c1a2 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Tue, 22 Jan 2019 20:51:12 +0300 Subject: [PATCH] Place instance markers in KotlinType hierarchy --- .../kotlin/descriptors/TypeParameterDescriptor.java | 3 ++- .../resolve/calls/inference/CapturedTypeConstructor.kt | 3 ++- .../src/org/jetbrains/kotlin/types/KotlinType.kt | 9 ++++++--- .../src/org/jetbrains/kotlin/types/RawType.kt | 4 +++- .../src/org/jetbrains/kotlin/types/SpecialTypes.kt | 5 ++++- .../src/org/jetbrains/kotlin/types/TypeConstructor.java | 3 ++- .../src/org/jetbrains/kotlin/types/TypeProjection.java | 3 ++- .../jetbrains/kotlin/types/checker/NewCapturedType.kt | 3 ++- .../src/org/jetbrains/kotlin/types/dynamicTypes.kt | 6 +++++- 9 files changed, 28 insertions(+), 11 deletions(-) diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/TypeParameterDescriptor.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/TypeParameterDescriptor.java index a1395ed7cb4..92515194cec 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/TypeParameterDescriptor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/TypeParameterDescriptor.java @@ -20,10 +20,11 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.types.KotlinType; import org.jetbrains.kotlin.types.TypeConstructor; import org.jetbrains.kotlin.types.Variance; +import org.jetbrains.kotlin.types.model.TypeParameterIM; import java.util.List; -public interface TypeParameterDescriptor extends ClassifierDescriptor { +public interface TypeParameterDescriptor extends ClassifierDescriptor, TypeParameterIM { boolean isReified(); @NotNull diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/CapturedTypeConstructor.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/CapturedTypeConstructor.kt index c2b2bea8205..fa1323338be 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/CapturedTypeConstructor.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/CapturedTypeConstructor.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.Variance.IN_VARIANCE import org.jetbrains.kotlin.types.Variance.OUT_VARIANCE import org.jetbrains.kotlin.types.checker.NewCapturedTypeConstructor +import org.jetbrains.kotlin.types.model.CapturedTypeIM import org.jetbrains.kotlin.types.typeUtil.builtIns interface CapturedTypeConstructor : TypeConstructor { @@ -68,7 +69,7 @@ class CapturedType( override val constructor: CapturedTypeConstructor = CapturedTypeConstructorImpl(typeProjection), override val isMarkedNullable: Boolean = false, override val annotations: Annotations = Annotations.EMPTY -) : SimpleType(), SubtypingRepresentatives { +) : SimpleType(), SubtypingRepresentatives, CapturedTypeIM { override val arguments: List get() = listOf() diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt index cceb0229a64..b2345aaac6e 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinType.kt @@ -22,6 +22,9 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.renderer.DescriptorRendererOptions import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.types.checker.StrictEqualityTypeChecker +import org.jetbrains.kotlin.types.model.FlexibleTypeIM +import org.jetbrains.kotlin.types.model.KotlinTypeIM +import org.jetbrains.kotlin.types.model.SimpleTypeIM /** * [KotlinType] has only two direct subclasses: [WrappedType] and [UnwrappedType]. @@ -40,7 +43,7 @@ import org.jetbrains.kotlin.types.checker.StrictEqualityTypeChecker * * For type creation see [KotlinTypeFactory]. */ -sealed class KotlinType : Annotated { +sealed class KotlinType : Annotated, KotlinTypeIM { abstract val constructor: TypeConstructor abstract val arguments: List @@ -119,7 +122,7 @@ sealed class UnwrappedType: KotlinType() { * then all your types are simple. * Or more precisely, all instances are subclasses of [SimpleType] or [WrappedType] (which contains [SimpleType] inside). */ -abstract class SimpleType : UnwrappedType() { +abstract class SimpleType : UnwrappedType(), SimpleTypeIM { abstract override fun replaceAnnotations(newAnnotations: Annotations): SimpleType abstract override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType @@ -138,7 +141,7 @@ abstract class SimpleType : UnwrappedType() { // lowerBound is a subtype of upperBound abstract class FlexibleType(val lowerBound: SimpleType, val upperBound: SimpleType) : - UnwrappedType(), SubtypingRepresentatives { + UnwrappedType(), SubtypingRepresentatives, FlexibleTypeIM { abstract val delegate: SimpleType diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/RawType.kt b/core/descriptors/src/org/jetbrains/kotlin/types/RawType.kt index 3dda769ef24..4bc82f3942a 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/RawType.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/RawType.kt @@ -16,4 +16,6 @@ package org.jetbrains.kotlin.types -interface RawType \ No newline at end of file +import org.jetbrains.kotlin.types.model.RawTypeIM + +interface RawType : RawTypeIM \ No newline at end of file diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/SpecialTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/types/SpecialTypes.kt index d5efe59d538..eee6d30d432 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/SpecialTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/SpecialTypes.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor import org.jetbrains.kotlin.types.checker.NullabilityChecker +import org.jetbrains.kotlin.types.model.DefinitelyNotNullTypeIM import org.jetbrains.kotlin.types.typeUtil.canHaveUndefinedNullability abstract class DelegatingSimpleType : SimpleType() { @@ -60,7 +61,9 @@ class LazyWrappedType(storageManager: StorageManager, computation: () -> KotlinT override fun isComputed(): Boolean = lazyValue.isComputed() } -class DefinitelyNotNullType private constructor(val original: SimpleType) : DelegatingSimpleType(), CustomTypeVariable { +class DefinitelyNotNullType private constructor(val original: SimpleType) : DelegatingSimpleType(), CustomTypeVariable, + DefinitelyNotNullTypeIM { + companion object { internal fun makeDefinitelyNotNull(type: UnwrappedType): DefinitelyNotNullType? { return when { diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeConstructor.java b/core/descriptors/src/org/jetbrains/kotlin/types/TypeConstructor.java index 0d12226c61a..e5008d51119 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeConstructor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeConstructor.java @@ -22,11 +22,12 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.descriptors.ClassifierDescriptor; import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor; +import org.jetbrains.kotlin.types.model.TypeConstructorIM; import java.util.Collection; import java.util.List; -public interface TypeConstructor { +public interface TypeConstructor extends TypeConstructorIM { /** * It may differ from ClassDescriptor.declaredParameters if the class is inner, in such case * it also contains additional parameters from outer declarations. diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeProjection.java b/core/descriptors/src/org/jetbrains/kotlin/types/TypeProjection.java index 346026017f8..3cc4cc59bc8 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeProjection.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeProjection.java @@ -17,8 +17,9 @@ package org.jetbrains.kotlin.types; import org.jetbrains.annotations.NotNull; +import org.jetbrains.kotlin.types.model.TypeArgumentIM; -public interface TypeProjection { +public interface TypeProjection extends TypeArgumentIM { @NotNull Variance getProjectionKind(); diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewCapturedType.kt b/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewCapturedType.kt index 6c1c891e1f4..fea9eec6d63 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewCapturedType.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/NewCapturedType.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.resolve.calls.inference.CapturedTypeConstructor import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.model.CapturedTypeIM import org.jetbrains.kotlin.types.typeUtil.asTypeProjection import org.jetbrains.kotlin.types.typeUtil.builtIns import org.jetbrains.kotlin.utils.DO_NOTHING_2 @@ -129,7 +130,7 @@ class NewCapturedType( val lowerType: UnwrappedType?, // todo check lower type for nullable captured types override val annotations: Annotations = Annotations.EMPTY, override val isMarkedNullable: Boolean = false -) : SimpleType() { +) : SimpleType(), CapturedTypeIM { internal constructor(captureStatus: CaptureStatus, lowerType: UnwrappedType?, projection: TypeProjection) : this(captureStatus, NewCapturedTypeConstructor(projection), lowerType) diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/dynamicTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/types/dynamicTypes.kt index f71d3dc2f19..27f5a724eb8 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/dynamicTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/dynamicTypes.kt @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.renderer.DescriptorRendererOptions +import org.jetbrains.kotlin.types.model.DynamicTypeIM import org.jetbrains.kotlin.types.typeUtil.builtIns open class DynamicTypesSettings { @@ -36,7 +37,10 @@ fun KotlinType.isDynamic(): Boolean = unwrap() is DynamicType fun createDynamicType(builtIns: KotlinBuiltIns) = DynamicType(builtIns, Annotations.EMPTY) -class DynamicType(builtIns: KotlinBuiltIns, override val annotations: Annotations) : FlexibleType(builtIns.nothingType, builtIns.nullableAnyType) { +class DynamicType( + builtIns: KotlinBuiltIns, + override val annotations: Annotations +) : FlexibleType(builtIns.nothingType, builtIns.nullableAnyType), DynamicTypeIM { override val delegate: SimpleType get() = upperBound // Nullability has no effect on dynamics