Place instance markers in KotlinType hierarchy

This commit is contained in:
Simon Ogorodnik
2019-01-22 20:51:12 +03:00
parent be79aeafa7
commit 8992537180
9 changed files with 28 additions and 11 deletions
@@ -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
@@ -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<TypeProjection>
get() = listOf()
@@ -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<TypeProjection>
@@ -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
@@ -16,4 +16,6 @@
package org.jetbrains.kotlin.types
interface RawType
import org.jetbrains.kotlin.types.model.RawTypeIM
interface RawType : RawTypeIM
@@ -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 {
@@ -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.
@@ -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();
@@ -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)
@@ -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