Place instance markers in KotlinType hierarchy
This commit is contained in:
@@ -20,10 +20,11 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.kotlin.types.KotlinType;
|
import org.jetbrains.kotlin.types.KotlinType;
|
||||||
import org.jetbrains.kotlin.types.TypeConstructor;
|
import org.jetbrains.kotlin.types.TypeConstructor;
|
||||||
import org.jetbrains.kotlin.types.Variance;
|
import org.jetbrains.kotlin.types.Variance;
|
||||||
|
import org.jetbrains.kotlin.types.model.TypeParameterIM;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface TypeParameterDescriptor extends ClassifierDescriptor {
|
public interface TypeParameterDescriptor extends ClassifierDescriptor, TypeParameterIM {
|
||||||
boolean isReified();
|
boolean isReified();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+2
-1
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.types.*
|
|||||||
import org.jetbrains.kotlin.types.Variance.IN_VARIANCE
|
import org.jetbrains.kotlin.types.Variance.IN_VARIANCE
|
||||||
import org.jetbrains.kotlin.types.Variance.OUT_VARIANCE
|
import org.jetbrains.kotlin.types.Variance.OUT_VARIANCE
|
||||||
import org.jetbrains.kotlin.types.checker.NewCapturedTypeConstructor
|
import org.jetbrains.kotlin.types.checker.NewCapturedTypeConstructor
|
||||||
|
import org.jetbrains.kotlin.types.model.CapturedTypeIM
|
||||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||||
|
|
||||||
interface CapturedTypeConstructor : TypeConstructor {
|
interface CapturedTypeConstructor : TypeConstructor {
|
||||||
@@ -68,7 +69,7 @@ class CapturedType(
|
|||||||
override val constructor: CapturedTypeConstructor = CapturedTypeConstructorImpl(typeProjection),
|
override val constructor: CapturedTypeConstructor = CapturedTypeConstructorImpl(typeProjection),
|
||||||
override val isMarkedNullable: Boolean = false,
|
override val isMarkedNullable: Boolean = false,
|
||||||
override val annotations: Annotations = Annotations.EMPTY
|
override val annotations: Annotations = Annotations.EMPTY
|
||||||
) : SimpleType(), SubtypingRepresentatives {
|
) : SimpleType(), SubtypingRepresentatives, CapturedTypeIM {
|
||||||
override val arguments: List<TypeProjection>
|
override val arguments: List<TypeProjection>
|
||||||
get() = listOf()
|
get() = listOf()
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
|||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions
|
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
import org.jetbrains.kotlin.types.checker.StrictEqualityTypeChecker
|
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].
|
* [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].
|
* For type creation see [KotlinTypeFactory].
|
||||||
*/
|
*/
|
||||||
sealed class KotlinType : Annotated {
|
sealed class KotlinType : Annotated, KotlinTypeIM {
|
||||||
|
|
||||||
abstract val constructor: TypeConstructor
|
abstract val constructor: TypeConstructor
|
||||||
abstract val arguments: List<TypeProjection>
|
abstract val arguments: List<TypeProjection>
|
||||||
@@ -119,7 +122,7 @@ sealed class UnwrappedType: KotlinType() {
|
|||||||
* then all your types are simple.
|
* then all your types are simple.
|
||||||
* Or more precisely, all instances are subclasses of [SimpleType] or [WrappedType] (which contains [SimpleType] inside).
|
* 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 replaceAnnotations(newAnnotations: Annotations): SimpleType
|
||||||
abstract override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType
|
abstract override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType
|
||||||
|
|
||||||
@@ -138,7 +141,7 @@ abstract class SimpleType : UnwrappedType() {
|
|||||||
|
|
||||||
// lowerBound is a subtype of upperBound
|
// lowerBound is a subtype of upperBound
|
||||||
abstract class FlexibleType(val lowerBound: SimpleType, val upperBound: SimpleType) :
|
abstract class FlexibleType(val lowerBound: SimpleType, val upperBound: SimpleType) :
|
||||||
UnwrappedType(), SubtypingRepresentatives {
|
UnwrappedType(), SubtypingRepresentatives, FlexibleTypeIM {
|
||||||
|
|
||||||
abstract val delegate: SimpleType
|
abstract val delegate: SimpleType
|
||||||
|
|
||||||
|
|||||||
@@ -16,4 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.types
|
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.storage.StorageManager
|
||||||
import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor
|
import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor
|
||||||
import org.jetbrains.kotlin.types.checker.NullabilityChecker
|
import org.jetbrains.kotlin.types.checker.NullabilityChecker
|
||||||
|
import org.jetbrains.kotlin.types.model.DefinitelyNotNullTypeIM
|
||||||
import org.jetbrains.kotlin.types.typeUtil.canHaveUndefinedNullability
|
import org.jetbrains.kotlin.types.typeUtil.canHaveUndefinedNullability
|
||||||
|
|
||||||
abstract class DelegatingSimpleType : SimpleType() {
|
abstract class DelegatingSimpleType : SimpleType() {
|
||||||
@@ -60,7 +61,9 @@ class LazyWrappedType(storageManager: StorageManager, computation: () -> KotlinT
|
|||||||
override fun isComputed(): Boolean = lazyValue.isComputed()
|
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 {
|
companion object {
|
||||||
internal fun makeDefinitelyNotNull(type: UnwrappedType): DefinitelyNotNullType? {
|
internal fun makeDefinitelyNotNull(type: UnwrappedType): DefinitelyNotNullType? {
|
||||||
return when {
|
return when {
|
||||||
|
|||||||
@@ -22,11 +22,12 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||||
|
import org.jetbrains.kotlin.types.model.TypeConstructorIM;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
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 may differ from ClassDescriptor.declaredParameters if the class is inner, in such case
|
||||||
* it also contains additional parameters from outer declarations.
|
* it also contains additional parameters from outer declarations.
|
||||||
|
|||||||
@@ -17,8 +17,9 @@
|
|||||||
package org.jetbrains.kotlin.types;
|
package org.jetbrains.kotlin.types;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.kotlin.types.model.TypeArgumentIM;
|
||||||
|
|
||||||
public interface TypeProjection {
|
public interface TypeProjection extends TypeArgumentIM {
|
||||||
@NotNull
|
@NotNull
|
||||||
Variance getProjectionKind();
|
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.calls.inference.CapturedTypeConstructor
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
import org.jetbrains.kotlin.types.*
|
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.asTypeProjection
|
||||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||||
import org.jetbrains.kotlin.utils.DO_NOTHING_2
|
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
|
val lowerType: UnwrappedType?, // todo check lower type for nullable captured types
|
||||||
override val annotations: Annotations = Annotations.EMPTY,
|
override val annotations: Annotations = Annotations.EMPTY,
|
||||||
override val isMarkedNullable: Boolean = false
|
override val isMarkedNullable: Boolean = false
|
||||||
) : SimpleType() {
|
) : SimpleType(), CapturedTypeIM {
|
||||||
internal constructor(captureStatus: CaptureStatus, lowerType: UnwrappedType?, projection: TypeProjection) :
|
internal constructor(captureStatus: CaptureStatus, lowerType: UnwrappedType?, projection: TypeProjection) :
|
||||||
this(captureStatus, NewCapturedTypeConstructor(projection), lowerType)
|
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.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions
|
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions
|
||||||
|
import org.jetbrains.kotlin.types.model.DynamicTypeIM
|
||||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||||
|
|
||||||
open class DynamicTypesSettings {
|
open class DynamicTypesSettings {
|
||||||
@@ -36,7 +37,10 @@ fun KotlinType.isDynamic(): Boolean = unwrap() is DynamicType
|
|||||||
|
|
||||||
fun createDynamicType(builtIns: KotlinBuiltIns) = DynamicType(builtIns, Annotations.EMPTY)
|
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
|
override val delegate: SimpleType get() = upperBound
|
||||||
|
|
||||||
// Nullability has no effect on dynamics
|
// Nullability has no effect on dynamics
|
||||||
|
|||||||
Reference in New Issue
Block a user