Remake KotlinTypes.
This commit is contained in:
+2
-2
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.serialization.SerializerExtension;
|
|||||||
import org.jetbrains.kotlin.serialization.StringTable;
|
import org.jetbrains.kotlin.serialization.StringTable;
|
||||||
import org.jetbrains.kotlin.serialization.jvm.ClassMapperLite;
|
import org.jetbrains.kotlin.serialization.jvm.ClassMapperLite;
|
||||||
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf;
|
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf;
|
||||||
import org.jetbrains.kotlin.types.DelegatingFlexibleType;
|
import org.jetbrains.kotlin.types.FlexibleType;
|
||||||
import org.jetbrains.kotlin.types.KotlinType;
|
import org.jetbrains.kotlin.types.KotlinType;
|
||||||
import org.jetbrains.org.objectweb.asm.Type;
|
import org.jetbrains.org.objectweb.asm.Type;
|
||||||
import org.jetbrains.org.objectweb.asm.commons.Method;
|
import org.jetbrains.org.objectweb.asm.commons.Method;
|
||||||
@@ -84,7 +84,7 @@ public class JvmSerializerExtension extends SerializerExtension {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serializeFlexibleType(
|
public void serializeFlexibleType(
|
||||||
@NotNull DelegatingFlexibleType flexibleType,
|
@NotNull FlexibleType flexibleType,
|
||||||
@NotNull ProtoBuf.Type.Builder lowerProto,
|
@NotNull ProtoBuf.Type.Builder lowerProto,
|
||||||
@NotNull ProtoBuf.Type.Builder upperProto
|
@NotNull ProtoBuf.Type.Builder upperProto
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -94,12 +94,12 @@ public class PossiblyBareType {
|
|||||||
|
|
||||||
KotlinType nullableActualType = TypeUtils.makeNullable(getActualType());
|
KotlinType nullableActualType = TypeUtils.makeNullable(getActualType());
|
||||||
|
|
||||||
KotlinType abbreviatedType = KotlinTypeKt.getAbbreviatedType(getActualType());
|
KotlinType abbreviatedType = SpecialTypesKt.getAbbreviatedType(getActualType());
|
||||||
if (abbreviatedType == null) {
|
if (abbreviatedType == null) {
|
||||||
return type(nullableActualType);
|
return type(nullableActualType);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return type(KotlinTypeKt.withAbbreviatedType(KotlinTypeKt.asSimpleType(nullableActualType), KotlinTypeKt.asSimpleType(TypeUtils.makeNullable(abbreviatedType))));
|
return type(SpecialTypesKt.withAbbreviatedType(KotlinTypeKt.asSimpleType(nullableActualType), KotlinTypeKt.asSimpleType(TypeUtils.makeNullable(abbreviatedType))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
|
|||||||
import org.jetbrains.kotlin.resolve.source.toSourceElement
|
import org.jetbrains.kotlin.resolve.source.toSourceElement
|
||||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||||
import org.jetbrains.kotlin.storage.StorageManager
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
|
import org.jetbrains.kotlin.storage.getValue
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.Variance.*
|
import org.jetbrains.kotlin.types.Variance.*
|
||||||
import org.jetbrains.kotlin.types.typeUtil.isArrayOfNothing
|
import org.jetbrains.kotlin.types.typeUtil.isArrayOfNothing
|
||||||
@@ -102,7 +103,7 @@ class TypeResolver(
|
|||||||
class LazyKotlinType : WrappedType(), LazyEntity {
|
class LazyKotlinType : WrappedType(), LazyEntity {
|
||||||
private val _delegate = storageManager.createLazyValue { doResolvePossiblyBareType(c, typeReference).getActualType() }
|
private val _delegate = storageManager.createLazyValue { doResolvePossiblyBareType(c, typeReference).getActualType() }
|
||||||
|
|
||||||
override fun unwrap() = _delegate()
|
override val delegate: KotlinType by _delegate
|
||||||
override fun isComputed() = _delegate.isComputed()
|
override fun isComputed() = _delegate.isComputed()
|
||||||
|
|
||||||
override fun forceResolveAllContents() {
|
override fun forceResolveAllContents() {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public class DeferredType extends WrappedType implements LazyType {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public KotlinType unwrap() {
|
public KotlinType getDelegate() {
|
||||||
return lazyValue.invoke();
|
return lazyValue.invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -506,7 +506,7 @@ public class DescriptorSerializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (FlexibleTypesKt.isFlexible(type)) {
|
if (FlexibleTypesKt.isFlexible(type)) {
|
||||||
DelegatingFlexibleType flexibleType = (DelegatingFlexibleType) FlexibleTypesKt.asFlexibleType(type);
|
FlexibleType flexibleType = FlexibleTypesKt.asFlexibleType(type);
|
||||||
|
|
||||||
ProtoBuf.Type.Builder lowerBound = type(flexibleType.getLowerBound());
|
ProtoBuf.Type.Builder lowerBound = type(flexibleType.getLowerBound());
|
||||||
ProtoBuf.Type.Builder upperBound = type(flexibleType.getUpperBound());
|
ProtoBuf.Type.Builder upperBound = type(flexibleType.getUpperBound());
|
||||||
@@ -548,7 +548,7 @@ public class DescriptorSerializer {
|
|||||||
builder.setNullable(type.isMarkedNullable());
|
builder.setNullable(type.isMarkedNullable());
|
||||||
}
|
}
|
||||||
|
|
||||||
KotlinType abbreviatedType = KotlinTypeKt.getAbbreviatedType(type);
|
KotlinType abbreviatedType = SpecialTypesKt.getAbbreviatedType(type);
|
||||||
if (abbreviatedType != null) {
|
if (abbreviatedType != null) {
|
||||||
if (useTypeTable()) {
|
if (useTypeTable()) {
|
||||||
builder.setAbbreviatedTypeId(typeId(abbreviatedType));
|
builder.setAbbreviatedTypeId(typeId(abbreviatedType));
|
||||||
|
|||||||
+2
-2
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.serialization;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.descriptors.*;
|
import org.jetbrains.kotlin.descriptors.*;
|
||||||
import org.jetbrains.kotlin.types.DelegatingFlexibleType;
|
import org.jetbrains.kotlin.types.FlexibleType;
|
||||||
import org.jetbrains.kotlin.types.KotlinType;
|
import org.jetbrains.kotlin.types.KotlinType;
|
||||||
|
|
||||||
public abstract class SerializerExtension {
|
public abstract class SerializerExtension {
|
||||||
@@ -50,7 +50,7 @@ public abstract class SerializerExtension {
|
|||||||
public void serializeValueParameter(@NotNull ValueParameterDescriptor descriptor, @NotNull ProtoBuf.ValueParameter.Builder proto) {
|
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 serializeFlexibleType(@NotNull FlexibleType flexibleType, @NotNull ProtoBuf.Type.Builder lowerProto, @NotNull ProtoBuf.Type.Builder upperProto) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void serializeType(@NotNull KotlinType type, @NotNull ProtoBuf.Type.Builder proto) {
|
public void serializeType(@NotNull KotlinType type, @NotNull ProtoBuf.Type.Builder proto) {
|
||||||
|
|||||||
+1
-1
@@ -9,5 +9,5 @@ Resolved call:
|
|||||||
Resulting descriptor: fun foo(): dynamic defined in bar
|
Resulting descriptor: fun foo(): dynamic defined in bar
|
||||||
|
|
||||||
Explicit receiver kind = DISPATCH_RECEIVER
|
Explicit receiver kind = DISPATCH_RECEIVER
|
||||||
Dispatch receiver = a {('Nothing'..'Any?')}
|
Dispatch receiver = a {dynamic}
|
||||||
Extension receiver = NO_RECEIVER
|
Extension receiver = NO_RECEIVER
|
||||||
|
|||||||
+1
-1
@@ -12,4 +12,4 @@ Resulting descriptor: fun dynamic.foo(): Unit defined in root package
|
|||||||
|
|
||||||
Explicit receiver kind = EXTENSION_RECEIVER
|
Explicit receiver kind = EXTENSION_RECEIVER
|
||||||
Dispatch receiver = NO_RECEIVER
|
Dispatch receiver = NO_RECEIVER
|
||||||
Extension receiver = a {('Nothing'..'Any?')}
|
Extension receiver = a {dynamic}
|
||||||
|
|||||||
+1
-1
@@ -16,4 +16,4 @@ Resulting descriptor: fun dynamic.foo(): Unit defined in A
|
|||||||
|
|
||||||
Explicit receiver kind = EXTENSION_RECEIVER
|
Explicit receiver kind = EXTENSION_RECEIVER
|
||||||
Dispatch receiver = AExt{fun A.<anonymous>(): Unit defined in bar}
|
Dispatch receiver = AExt{fun A.<anonymous>(): Unit defined in bar}
|
||||||
Extension receiver = b {('Nothing'..'Any?')}
|
Extension receiver = b {dynamic}
|
||||||
|
|||||||
+1
-1
@@ -18,4 +18,4 @@ Resulting descriptor: fun dynamic.foo(): Unit defined in A
|
|||||||
|
|
||||||
Explicit receiver kind = NO_EXPLICIT_RECEIVER
|
Explicit receiver kind = NO_EXPLICIT_RECEIVER
|
||||||
Dispatch receiver = AExt{fun A.<anonymous>(): Unit defined in bar}
|
Dispatch receiver = AExt{fun A.<anonymous>(): Unit defined in bar}
|
||||||
Extension receiver = ('Nothing'..'Any?')Ext{fun dynamic.<anonymous>(): Unit defined in bar.<anonymous>}
|
Extension receiver = dynamicExt{fun dynamic.<anonymous>(): Unit defined in bar.<anonymous>}
|
||||||
|
|||||||
+1
-1
@@ -9,5 +9,5 @@ Resolved call:
|
|||||||
Resulting descriptor: fun foo(): dynamic defined in bar
|
Resulting descriptor: fun foo(): dynamic defined in bar
|
||||||
|
|
||||||
Explicit receiver kind = NO_EXPLICIT_RECEIVER
|
Explicit receiver kind = NO_EXPLICIT_RECEIVER
|
||||||
Dispatch receiver = ('Nothing'..'Any?')Ext{fun dynamic.bar(): Unit defined in root package}
|
Dispatch receiver = dynamicExt{fun dynamic.bar(): Unit defined in root package}
|
||||||
Extension receiver = NO_RECEIVER
|
Extension receiver = NO_RECEIVER
|
||||||
|
|||||||
+1
-1
@@ -12,4 +12,4 @@ Resulting descriptor: fun dynamic.foo(): Unit defined in root package
|
|||||||
|
|
||||||
Explicit receiver kind = NO_EXPLICIT_RECEIVER
|
Explicit receiver kind = NO_EXPLICIT_RECEIVER
|
||||||
Dispatch receiver = NO_RECEIVER
|
Dispatch receiver = NO_RECEIVER
|
||||||
Extension receiver = ('Nothing'..'Any?')Ext{fun dynamic.bar(): Unit defined in root package}
|
Extension receiver = dynamicExt{fun dynamic.bar(): Unit defined in root package}
|
||||||
|
|||||||
+3
-3
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -19,12 +19,12 @@ package org.jetbrains.kotlin.test;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||||
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase;
|
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase;
|
||||||
import org.jetbrains.kotlin.types.DelegatingFlexibleType;
|
import org.jetbrains.kotlin.types.FlexibleTypeImpl;
|
||||||
|
|
||||||
public abstract class KotlinTestWithEnvironmentManagement extends KtUsefulTestCase {
|
public abstract class KotlinTestWithEnvironmentManagement extends KtUsefulTestCase {
|
||||||
static {
|
static {
|
||||||
System.setProperty("java.awt.headless", "true");
|
System.setProperty("java.awt.headless", "true");
|
||||||
DelegatingFlexibleType.RUN_SLOW_ASSERTIONS = true;
|
FlexibleTypeImpl.RUN_SLOW_ASSERTIONS = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.serialization.ProtoBuf
|
|||||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationContext
|
import org.jetbrains.kotlin.serialization.deserialization.DeserializationContext
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.TypeDeserializer
|
import org.jetbrains.kotlin.serialization.deserialization.TypeDeserializer
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.KotlinTypeImpl
|
|
||||||
import org.jetbrains.kotlin.utils.Printer
|
import org.jetbrains.kotlin.utils.Printer
|
||||||
import java.lang.reflect.Constructor
|
import java.lang.reflect.Constructor
|
||||||
import java.lang.reflect.GenericDeclaration
|
import java.lang.reflect.GenericDeclaration
|
||||||
@@ -177,7 +176,7 @@ class LazyOperationsLog(
|
|||||||
o.joinTo(sb, ", ", prefix = "{", postfix = "}", limit = 3) { render(it) }
|
o.joinTo(sb, ", ", prefix = "{", postfix = "}", limit = 3) { render(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
o is KotlinTypeImpl -> {
|
o is KotlinType -> {
|
||||||
StringBuilder().apply {
|
StringBuilder().apply {
|
||||||
append(o.constructor)
|
append(o.constructor)
|
||||||
if (!o.arguments.isEmpty()) {
|
if (!o.arguments.isEmpty()) {
|
||||||
|
|||||||
-1
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.load.java.lazy.types.RawTypeImpl
|
|||||||
import org.jetbrains.kotlin.resolve.ExternalOverridabilityCondition
|
import org.jetbrains.kotlin.resolve.ExternalOverridabilityCondition
|
||||||
import org.jetbrains.kotlin.resolve.ExternalOverridabilityCondition.Result
|
import org.jetbrains.kotlin.resolve.ExternalOverridabilityCondition.Result
|
||||||
import org.jetbrains.kotlin.resolve.OverridingUtil
|
import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||||
import org.jetbrains.kotlin.types.unwrap
|
|
||||||
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
||||||
|
|
||||||
class ErasedOverridabilityCondition : ExternalOverridabilityCondition {
|
class ErasedOverridabilityCondition : ExternalOverridabilityCondition {
|
||||||
|
|||||||
+4
-4
@@ -115,10 +115,10 @@ class LazyJavaTypeResolver(
|
|||||||
) : AbstractLazyType(c.storageManager) {
|
) : AbstractLazyType(c.storageManager) {
|
||||||
override val annotations = CompositeAnnotations(listOf(LazyJavaAnnotations(c, javaType), attr.typeAnnotations))
|
override val annotations = CompositeAnnotations(listOf(LazyJavaAnnotations(c, javaType), attr.typeAnnotations))
|
||||||
|
|
||||||
private val classifier = c.storageManager.createNullableLazyValue { javaType.classifier }
|
private val classifier: JavaClassifier? get() = javaType.classifier
|
||||||
|
|
||||||
override fun computeTypeConstructor(): TypeConstructor {
|
override fun computeTypeConstructor(): TypeConstructor {
|
||||||
val classifier = classifier() ?: return createNotFoundClass()
|
val classifier = classifier ?: return createNotFoundClass()
|
||||||
return when (classifier) {
|
return when (classifier) {
|
||||||
is JavaClass -> {
|
is JavaClass -> {
|
||||||
val fqName = classifier.fqName.sure { "Class type should have a FQ name: $classifier" }
|
val fqName = classifier.fqName.sure { "Class type should have a FQ name: $classifier" }
|
||||||
@@ -279,13 +279,13 @@ class LazyJavaTypeResolver(
|
|||||||
!attr.isMarkedNotNull &&
|
!attr.isMarkedNotNull &&
|
||||||
// 'L extends List<T>' in Java is a List<T> in Kotlin, not a List<T?>
|
// 'L extends List<T>' in Java is a List<T> in Kotlin, not a List<T?>
|
||||||
// nullability will be taken care of in individual member signatures
|
// nullability will be taken care of in individual member signatures
|
||||||
when (classifier()) {
|
when (classifier) {
|
||||||
is JavaTypeParameter -> {
|
is JavaTypeParameter -> {
|
||||||
attr.howThisTypeIsUsed !in setOf(TYPE_ARGUMENT, UPPER_BOUND, SUPERTYPE_ARGUMENT, SUPERTYPE)
|
attr.howThisTypeIsUsed !in setOf(TYPE_ARGUMENT, UPPER_BOUND, SUPERTYPE_ARGUMENT, SUPERTYPE)
|
||||||
}
|
}
|
||||||
is JavaClass,
|
is JavaClass,
|
||||||
null -> attr.howThisTypeIsUsed !in setOf(TYPE_ARGUMENT, SUPERTYPE_ARGUMENT, SUPERTYPE)
|
null -> attr.howThisTypeIsUsed !in setOf(TYPE_ARGUMENT, SUPERTYPE_ARGUMENT, SUPERTYPE)
|
||||||
else -> error("Unknown classifier: ${classifier()}")
|
else -> error("Unknown classifier: ${classifier}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-8
@@ -27,17 +27,15 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
|||||||
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.checker.KotlinTypeChecker
|
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||||
import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations
|
|
||||||
|
|
||||||
class RawTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : DelegatingFlexibleType(lowerBound, upperBound), RawType {
|
class RawTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : FlexibleType(lowerBound, upperBound), RawType {
|
||||||
init {
|
init {
|
||||||
assert (KotlinTypeChecker.DEFAULT.isSubtypeOf(lowerBound, upperBound)) {
|
assert (KotlinTypeChecker.DEFAULT.isSubtypeOf(lowerBound, upperBound)) {
|
||||||
"Lower bound $lowerBound of a flexible type must be a subtype of the upper bound $upperBound"
|
"Lower bound $lowerBound of a flexible type must be a subtype of the upper bound $upperBound"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
override fun getDelegate(): KotlinType = delegateType
|
|
||||||
|
|
||||||
override val delegateType: KotlinType get() = lowerBound
|
override val delegate: SimpleType get() = lowerBound
|
||||||
|
|
||||||
override val memberScope: MemberScope
|
override val memberScope: MemberScope
|
||||||
get() {
|
get() {
|
||||||
@@ -46,11 +44,11 @@ class RawTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : DelegatingFl
|
|||||||
return classDescriptor.getMemberScope(RawSubstitution)
|
return classDescriptor.getMemberScope(RawSubstitution)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations): KotlinType
|
override fun replaceAnnotations(newAnnotations: Annotations)
|
||||||
= RawTypeImpl(lowerBound.replaceAnnotations(newAnnotations).asSimpleType(), upperBound)
|
= RawTypeImpl(lowerBound.replaceAnnotations(newAnnotations), upperBound.replaceAnnotations(newAnnotations))
|
||||||
|
|
||||||
override fun makeNullableAsSpecified(nullable: Boolean): KotlinType
|
override fun makeNullableAsSpecified(newNullability: Boolean)
|
||||||
= RawTypeImpl(TypeUtils.makeNullableAsSpecified(lowerBound, nullable), TypeUtils.makeNullableAsSpecified(upperBound, nullable))
|
= RawTypeImpl(lowerBound.makeNullableAsSpecified(newNullability), upperBound.makeNullableAsSpecified(newNullability))
|
||||||
|
|
||||||
override fun render(renderer: DescriptorRenderer, options: DescriptorRendererOptions): String {
|
override fun render(renderer: DescriptorRenderer, options: DescriptorRendererOptions): String {
|
||||||
fun onlyOutDiffers(first: String, second: String) = first == second.removePrefix("out ") || second == "*"
|
fun onlyOutDiffers(first: String, second: String) = first == second.removePrefix("out ") || second == "*"
|
||||||
|
|||||||
+10
-5
@@ -124,14 +124,14 @@ private fun KotlinType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers
|
|||||||
|
|
||||||
val newSubstitution = TypeConstructorSubstitution.create(typeConstructor, enhancedArguments)
|
val newSubstitution = TypeConstructorSubstitution.create(typeConstructor, enhancedArguments)
|
||||||
|
|
||||||
val enhancedType = KotlinTypeImpl.create(
|
val enhancedType = KotlinTypeFactory.simpleType(
|
||||||
newAnnotations,
|
newAnnotations,
|
||||||
typeConstructor,
|
typeConstructor,
|
||||||
enhancedNullability,
|
|
||||||
enhancedArguments,
|
enhancedArguments,
|
||||||
|
enhancedNullability,
|
||||||
if (enhancedClassifier is ClassDescriptor)
|
if (enhancedClassifier is ClassDescriptor)
|
||||||
enhancedClassifier.getMemberScope(newSubstitution)
|
enhancedClassifier.getMemberScope(newSubstitution)
|
||||||
else enhancedClassifier.getDefaultType().memberScope
|
else enhancedClassifier.defaultType.memberScope
|
||||||
)
|
)
|
||||||
|
|
||||||
val result = if (effectiveQualifiers.isNotNullTypeParameter) NotNullTypeParameter(enhancedType) else enhancedType
|
val result = if (effectiveQualifiers.isNotNullTypeParameter) NotNullTypeParameter(enhancedType) else enhancedType
|
||||||
@@ -213,8 +213,7 @@ private object EnhancedTypeAnnotationDescriptor : AnnotationDescriptor {
|
|||||||
override fun toString() = "[EnhancedType]"
|
override fun toString() = "[EnhancedType]"
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class NotNullTypeParameter(private val delegate: SimpleType) : CustomTypeVariable, DelegatingType(), SimpleType {
|
internal class NotNullTypeParameter(override val delegate: SimpleType) : CustomTypeVariable, DelegatingSimpleType() {
|
||||||
override fun getDelegate(): KotlinType? = delegate
|
|
||||||
|
|
||||||
override val isTypeVariable: Boolean
|
override val isTypeVariable: Boolean
|
||||||
get() = true
|
get() = true
|
||||||
@@ -240,4 +239,10 @@ internal class NotNullTypeParameter(private val delegate: SimpleType) : CustomTy
|
|||||||
|
|
||||||
return NotNullTypeParameter(result)
|
return NotNullTypeParameter(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun replaceAnnotations(newAnnotations: Annotations) = NotNullTypeParameter(delegate.replaceAnnotations(newAnnotations))
|
||||||
|
override fun makeNullableAsSpecified(newNullability: Boolean) = this
|
||||||
|
|
||||||
|
override val isError: Boolean
|
||||||
|
get() = false
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -78,7 +78,7 @@ open class JvmBuiltInsSettings(
|
|||||||
|
|
||||||
//NOTE: can't reference anyType right away, because this is sometimes called when JvmBuiltIns are initializing
|
//NOTE: can't reference anyType right away, because this is sometimes called when JvmBuiltIns are initializing
|
||||||
val superTypes = listOf(object : WrappedType() {
|
val superTypes = listOf(object : WrappedType() {
|
||||||
override fun unwrap() = moduleDescriptor.builtIns.anyType
|
override val delegate: KotlinType get() = moduleDescriptor.builtIns.anyType
|
||||||
})
|
})
|
||||||
|
|
||||||
val mockSerializableClass = ClassDescriptorImpl(
|
val mockSerializableClass = ClassDescriptorImpl(
|
||||||
|
|||||||
+8
-7
@@ -62,7 +62,7 @@ class CapturedType(
|
|||||||
override val constructor: TypeConstructor = CapturedTypeConstructor(typeProjection),
|
override val constructor: TypeConstructor = CapturedTypeConstructor(typeProjection),
|
||||||
override val isMarkedNullable: Boolean = false,
|
override val isMarkedNullable: Boolean = false,
|
||||||
override val annotations: Annotations = Annotations.EMPTY
|
override val annotations: Annotations = Annotations.EMPTY
|
||||||
): AbstractKotlinType(), SubtypingRepresentatives, TypeWithCustomReplacement {
|
): SimpleType(), SubtypingRepresentatives {
|
||||||
|
|
||||||
override val arguments: List<TypeProjection>
|
override val arguments: List<TypeProjection>
|
||||||
get() = listOf()
|
get() = listOf()
|
||||||
@@ -83,14 +83,14 @@ class CapturedType(
|
|||||||
|
|
||||||
override fun sameTypeConstructor(type: KotlinType) = constructor === type.constructor
|
override fun sameTypeConstructor(type: KotlinType) = constructor === type.constructor
|
||||||
|
|
||||||
override fun toString() = "Captured($typeProjection)${if (isMarkedNullable) '?' else ""}"
|
override fun toString() = "Captured($typeProjection)" + if (isMarkedNullable) "?" else ""
|
||||||
|
|
||||||
override fun makeNullableAsSpecified(nullable: Boolean): KotlinType {
|
override fun makeNullableAsSpecified(newNullability: Boolean): CapturedType {
|
||||||
if (nullable == isMarkedNullable) return this
|
if (newNullability == isMarkedNullable) return this
|
||||||
return CapturedType(typeProjection, constructor, nullable, annotations)
|
return CapturedType(typeProjection, constructor, newNullability, annotations)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations): KotlinType = CapturedType(typeProjection, constructor, isMarkedNullable, newAnnotations)
|
override fun replaceAnnotations(newAnnotations: Annotations): CapturedType = CapturedType(typeProjection, constructor, isMarkedNullable, newAnnotations)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createCapturedType(typeProjection: TypeProjection): KotlinType
|
fun createCapturedType(typeProjection: TypeProjection): KotlinType
|
||||||
@@ -120,7 +120,8 @@ private fun TypeProjection.createCapturedIfNeeded(typeParameterDescriptor: TypeP
|
|||||||
// TODO: Make star projection type lazy
|
// TODO: Make star projection type lazy
|
||||||
return if (isStarProjection)
|
return if (isStarProjection)
|
||||||
TypeProjectionImpl(object : WrappedType() {
|
TypeProjectionImpl(object : WrappedType() {
|
||||||
override fun unwrap(): KotlinType = this@createCapturedIfNeeded.type
|
override val delegate: KotlinType
|
||||||
|
get() = this@createCapturedIfNeeded.type
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
TypeProjectionImpl(this@createCapturedIfNeeded.type)
|
TypeProjectionImpl(this@createCapturedIfNeeded.type)
|
||||||
|
|||||||
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.types;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget;
|
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class AbstractKotlinType implements KotlinType, SimpleType { // TODO temporary upper bound
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final int hashCode() {
|
|
||||||
int result = getConstructor().hashCode();
|
|
||||||
result = 31 * result + getArguments().hashCode();
|
|
||||||
result = 31 * result + (isMarkedNullable() ? 1 : 0);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean equals(Object obj) {
|
|
||||||
if (this == obj) return true;
|
|
||||||
if (!(obj instanceof KotlinType)) return false;
|
|
||||||
|
|
||||||
KotlinType type = (KotlinType) obj;
|
|
||||||
|
|
||||||
return isMarkedNullable() == type.isMarkedNullable() && KotlinTypeChecker.FLEXIBLE_UNEQUAL_TO_INFLEXIBLE.equalTypes(this, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
|
|
||||||
for (AnnotationWithTarget annotationWithTarget : getAnnotations().getAllAnnotations()) {
|
|
||||||
sb.append("[");
|
|
||||||
sb.append(DescriptorRenderer.DEBUG_TEXT.renderAnnotation(
|
|
||||||
annotationWithTarget.getAnnotation(), annotationWithTarget.getTarget()));
|
|
||||||
sb.append("] ");
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append(getConstructor());
|
|
||||||
|
|
||||||
List<TypeProjection> arguments = getArguments();
|
|
||||||
if (!arguments.isEmpty()) {
|
|
||||||
sb.append("<");
|
|
||||||
for (Iterator<TypeProjection> i = arguments.iterator(); i.hasNext(); ) {
|
|
||||||
sb.append(i.next());
|
|
||||||
if (i.hasNext()) {
|
|
||||||
sb.append(", ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sb.append(">");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isMarkedNullable()) {
|
|
||||||
sb.append("?");
|
|
||||||
}
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public SimpleType getAbbreviatedType() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
|||||||
import org.jetbrains.kotlin.storage.StorageManager
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
import org.jetbrains.kotlin.storage.getValue
|
import org.jetbrains.kotlin.storage.getValue
|
||||||
|
|
||||||
abstract class AbstractLazyType(storageManager: StorageManager) : AbstractKotlinType(), SimpleType, LazyType {
|
abstract class AbstractLazyType(storageManager: StorageManager) : SimpleType(), LazyType {
|
||||||
|
|
||||||
private val typeConstructor = storageManager.createLazyValue { computeTypeConstructor() }
|
private val typeConstructor = storageManager.createLazyValue { computeTypeConstructor() }
|
||||||
override val constructor by typeConstructor
|
override val constructor by typeConstructor
|
||||||
@@ -52,6 +52,10 @@ abstract class AbstractLazyType(storageManager: StorageManager) : AbstractKotlin
|
|||||||
|
|
||||||
override val annotations: Annotations get() = Annotations.EMPTY
|
override val annotations: Annotations get() = Annotations.EMPTY
|
||||||
|
|
||||||
|
// TODO: do not force resolution
|
||||||
|
override fun replaceAnnotations(newAnnotations: Annotations): SimpleType = KotlinTypeFactory.simpleType(this, annotations = newAnnotations)
|
||||||
|
override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType = KotlinTypeFactory.simpleType(this, nullable = newNullability)
|
||||||
|
|
||||||
override fun toString() = when {
|
override fun toString() = when {
|
||||||
!typeConstructor.isComputed() -> "[Not-computed]"
|
!typeConstructor.isComputed() -> "[Not-computed]"
|
||||||
!_arguments.isComputed() ->
|
!_arguments.isComputed() ->
|
||||||
|
|||||||
@@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.types;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class DelegatingType implements KotlinType, SimpleType { // TODO temporary upper bound
|
|
||||||
protected abstract KotlinType getDelegate();
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public TypeConstructor getConstructor() {
|
|
||||||
return getDelegate().getConstructor();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public List<TypeProjection> getArguments() {
|
|
||||||
return getDelegate().getArguments();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isMarkedNullable() {
|
|
||||||
return getDelegate().isMarkedNullable();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public MemberScope getMemberScope() {
|
|
||||||
return getDelegate().getMemberScope();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isError() {
|
|
||||||
return getDelegate().isError();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Annotations getAnnotations() {
|
|
||||||
return getDelegate().getAnnotations();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return getDelegate().hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj) return true;
|
|
||||||
if (!(obj instanceof KotlinType)) return false;
|
|
||||||
|
|
||||||
KotlinType type = (KotlinType) obj;
|
|
||||||
return KotlinTypeChecker.FLEXIBLE_UNEQUAL_TO_INFLEXIBLE.equalTypes(this, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return getDelegate().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public SimpleType getAbbreviatedType() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -390,7 +390,7 @@ public class ErrorUtils {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static SimpleType createErrorTypeWithArguments(@NotNull String debugMessage, @NotNull List<TypeProjection> arguments) {
|
public static SimpleType createErrorTypeWithArguments(@NotNull String debugMessage, @NotNull List<TypeProjection> arguments) {
|
||||||
return new ErrorTypeImpl(createErrorTypeConstructor(debugMessage), createErrorScope(debugMessage), arguments);
|
return new ErrorTypeImpl(createErrorTypeConstructor(debugMessage), createErrorScope(debugMessage), arguments, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -472,35 +472,26 @@ public class ErrorUtils {
|
|||||||
return candidate instanceof ErrorClassDescriptor;
|
return candidate instanceof ErrorClassDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
private static class ErrorTypeImpl extends SimpleType {
|
||||||
public static TypeParameterDescriptor createErrorTypeParameter(int index, @NotNull String debugMessage) {
|
|
||||||
return TypeParameterDescriptorImpl.createWithDefaultBound(
|
|
||||||
ERROR_CLASS,
|
|
||||||
Annotations.Companion.getEMPTY(),
|
|
||||||
false,
|
|
||||||
Variance.INVARIANT,
|
|
||||||
Name.special("<ERROR: " + debugMessage + ">"),
|
|
||||||
index
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ErrorTypeImpl implements SimpleType {
|
|
||||||
private final TypeConstructor constructor;
|
private final TypeConstructor constructor;
|
||||||
private final MemberScope memberScope;
|
private final MemberScope memberScope;
|
||||||
private final List<TypeProjection> arguments;
|
private final List<TypeProjection> arguments;
|
||||||
|
private final boolean nullability;
|
||||||
|
|
||||||
private ErrorTypeImpl(
|
private ErrorTypeImpl(
|
||||||
@NotNull TypeConstructor constructor,
|
@NotNull TypeConstructor constructor,
|
||||||
@NotNull MemberScope memberScope,
|
@NotNull MemberScope memberScope,
|
||||||
@NotNull List<TypeProjection> arguments
|
@NotNull List<TypeProjection> arguments,
|
||||||
|
boolean nullability
|
||||||
) {
|
) {
|
||||||
this.constructor = constructor;
|
this.constructor = constructor;
|
||||||
this.memberScope = memberScope;
|
this.memberScope = memberScope;
|
||||||
this.arguments = arguments;
|
this.arguments = arguments;
|
||||||
|
this.nullability = nullability;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ErrorTypeImpl(@NotNull TypeConstructor constructor, @NotNull MemberScope memberScope) {
|
private ErrorTypeImpl(@NotNull TypeConstructor constructor, @NotNull MemberScope memberScope) {
|
||||||
this(constructor, memberScope, Collections.<TypeProjection>emptyList());
|
this(constructor, memberScope, Collections.<TypeProjection>emptyList(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -517,7 +508,7 @@ public class ErrorUtils {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMarkedNullable() {
|
public boolean isMarkedNullable() {
|
||||||
return false;
|
return nullability;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -542,10 +533,16 @@ public class ErrorUtils {
|
|||||||
return constructor.toString() + (arguments.isEmpty() ? "" : joinToString(arguments, ", ", "<", ">", -1, "...", null));
|
return constructor.toString() + (arguments.isEmpty() ? "" : joinToString(arguments, ", ", "<", ">", -1, "...", null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public SimpleType getAbbreviatedType() {
|
public SimpleType replaceAnnotations(@NotNull Annotations newAnnotations) {
|
||||||
return null;
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public SimpleType makeNullableAsSpecified(boolean newNullability) {
|
||||||
|
return new ErrorTypeImpl(constructor, memberScope, arguments, newNullability);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,59 +19,59 @@ package org.jetbrains.kotlin.types
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotated
|
import org.jetbrains.kotlin.descriptors.annotations.Annotated
|
||||||
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.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see KotlinTypeChecker.isSubtypeOf
|
* @see KotlinTypeChecker.isSubtypeOf
|
||||||
*/
|
*/
|
||||||
interface KotlinType : Annotated {
|
sealed class KotlinType : Annotated {
|
||||||
val constructor: TypeConstructor
|
|
||||||
|
|
||||||
val arguments: List<TypeProjection>
|
abstract val constructor: TypeConstructor
|
||||||
|
abstract val arguments: List<TypeProjection>
|
||||||
|
abstract val isMarkedNullable: Boolean
|
||||||
|
abstract val memberScope: MemberScope
|
||||||
|
abstract val isError: Boolean
|
||||||
|
|
||||||
val isMarkedNullable: Boolean
|
abstract fun unwrap(): UnwrappedType
|
||||||
|
|
||||||
val memberScope: MemberScope
|
// ------- internal staff ------
|
||||||
|
|
||||||
val isError: Boolean
|
final override fun hashCode(): Int {
|
||||||
|
if (isError) return super.hashCode()
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean
|
var result = constructor.hashCode()
|
||||||
|
result = 31 * result + arguments.hashCode()
|
||||||
|
result = 31 * result + if (isMarkedNullable) 1 else 0
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
final override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (other !is KotlinType) return false
|
||||||
|
|
||||||
|
return isMarkedNullable == other.isMarkedNullable && KotlinTypeChecker.FLEXIBLE_UNEQUAL_TO_INFLEXIBLE.equalTypes(this, other)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Temporary marker method for refactoring")
|
abstract class WrappedType() : KotlinType(), LazyType {
|
||||||
fun KotlinType.asSimpleType(): SimpleType {
|
open fun isComputed(): Boolean = true
|
||||||
return unwrap() as SimpleType
|
protected abstract val delegate: KotlinType
|
||||||
}
|
|
||||||
|
|
||||||
fun KotlinType.unwrap(): KotlinType {
|
|
||||||
if (this is WrappedType) return unwrap().unwrap()
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SimpleType : KotlinType {
|
|
||||||
val abbreviatedType : SimpleType? get() = null
|
|
||||||
}
|
|
||||||
|
|
||||||
interface TypeWithCustomReplacement : KotlinType {
|
|
||||||
fun makeNullableAsSpecified(nullable: Boolean): KotlinType
|
|
||||||
|
|
||||||
fun replaceAnnotations(newAnnotations: Annotations): KotlinType
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class WrappedType() : KotlinType, LazyType {
|
|
||||||
override val annotations: Annotations get() = delegate.annotations
|
override val annotations: Annotations get() = delegate.annotations
|
||||||
override val constructor: TypeConstructor get() = delegate.constructor
|
override val constructor: TypeConstructor get() = delegate.constructor
|
||||||
override val arguments: List<TypeProjection> get() = delegate.arguments
|
override val arguments: List<TypeProjection> get() = delegate.arguments
|
||||||
override val isMarkedNullable: Boolean get() = delegate.isMarkedNullable
|
override val isMarkedNullable: Boolean get() = delegate.isMarkedNullable
|
||||||
override val memberScope: MemberScope get() = delegate.memberScope
|
override val memberScope: MemberScope get() = delegate.memberScope
|
||||||
|
|
||||||
|
override final fun unwrap(): UnwrappedType {
|
||||||
open fun isComputed(): Boolean = true
|
var result = delegate
|
||||||
open val delegate: KotlinType
|
while (result is WrappedType) {
|
||||||
get() = unwrap()
|
result = result.delegate
|
||||||
|
}
|
||||||
abstract fun unwrap(): KotlinType
|
return result as UnwrappedType
|
||||||
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
if (isComputed()) {
|
if (isComputed()) {
|
||||||
@@ -84,58 +84,26 @@ abstract class WrappedType() : KotlinType, LazyType {
|
|||||||
|
|
||||||
// todo: remove this later
|
// todo: remove this later
|
||||||
override val isError: Boolean get() = delegate.isError
|
override val isError: Boolean get() = delegate.isError
|
||||||
override fun equals(other: Any?): Boolean = unwrap().equals(other)
|
|
||||||
override fun hashCode(): Int = unwrap().hashCode()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun SimpleType.lazyReplaceNullability(newNullable: Boolean): SimpleType {
|
sealed class UnwrappedType: KotlinType() {
|
||||||
if (this is WrappedSimpleType) {
|
abstract fun replaceAnnotations(newAnnotations: Annotations): UnwrappedType
|
||||||
return WrappedSimpleType(delegate, newAnnotations, newNullable)
|
abstract fun makeNullableAsSpecified(newNullability: Boolean): UnwrappedType
|
||||||
}
|
|
||||||
else {
|
override final fun unwrap(): UnwrappedType = this
|
||||||
return WrappedSimpleType(this, newNullable = newNullable)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun SimpleType.lazyReplaceAnnotations(newAnnotations: Annotations): SimpleType {
|
abstract class SimpleType : UnwrappedType() {
|
||||||
if (this is WrappedSimpleType) {
|
abstract override fun replaceAnnotations(newAnnotations: Annotations): SimpleType
|
||||||
return WrappedSimpleType(delegate, newAnnotations, newNullable)
|
abstract override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType
|
||||||
}
|
|
||||||
else {
|
|
||||||
return WrappedSimpleType(this, newAnnotations)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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, abbreviatedType)
|
|
||||||
}
|
|
||||||
|
|
||||||
private class WrappedSimpleType(
|
|
||||||
override val delegate: SimpleType,
|
|
||||||
val newAnnotations: Annotations? = null,
|
|
||||||
val newNullable: Boolean? = null
|
|
||||||
): WrappedType(), SimpleType {
|
|
||||||
override val annotations: Annotations
|
|
||||||
get() = newAnnotations ?: delegate.annotations
|
|
||||||
|
|
||||||
override val isMarkedNullable: Boolean
|
|
||||||
get() = newNullable ?: delegate.isMarkedNullable
|
|
||||||
|
|
||||||
override fun unwrap(): KotlinType {
|
|
||||||
if (delegate.isError) return delegate // todo
|
|
||||||
if (delegate is CustomTypeVariable) return delegate // todo
|
|
||||||
return KotlinTypeImpl.create(annotations, constructor, isMarkedNullable, arguments, memberScope, abbreviatedType)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
if (isError) return delegate.toString()
|
// for error types this method should be overridden
|
||||||
|
if (isError) return "ErrorType"
|
||||||
|
|
||||||
return buildString {
|
return buildString {
|
||||||
for (annotation in annotations.getAllAnnotations()) {
|
for ((annotation, target) in annotations.getAllAnnotations()) {
|
||||||
append("[", DescriptorRenderer.DEBUG_TEXT.renderAnnotation(annotation.annotation, annotation.target), "] ")
|
append("[", DescriptorRenderer.DEBUG_TEXT.renderAnnotation(annotation, target), "] ")
|
||||||
}
|
}
|
||||||
|
|
||||||
append(constructor)
|
append(constructor)
|
||||||
@@ -143,4 +111,34 @@ private class WrappedSimpleType(
|
|||||||
if (isMarkedNullable) append("?")
|
if (isMarkedNullable) append("?")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lowerBound is a subtype of upperBound
|
||||||
|
abstract class FlexibleType(val lowerBound: SimpleType, val upperBound: SimpleType) :
|
||||||
|
UnwrappedType(), SubtypingRepresentatives {
|
||||||
|
|
||||||
|
abstract val delegate: SimpleType
|
||||||
|
|
||||||
|
override val subTypeRepresentative: KotlinType
|
||||||
|
get() = lowerBound
|
||||||
|
override val superTypeRepresentative: KotlinType
|
||||||
|
get() = upperBound
|
||||||
|
|
||||||
|
override fun sameTypeConstructor(type: KotlinType) = false
|
||||||
|
|
||||||
|
abstract fun render(renderer: DescriptorRenderer, options: DescriptorRendererOptions): String
|
||||||
|
|
||||||
|
override val annotations: Annotations get() = delegate.annotations
|
||||||
|
override val constructor: TypeConstructor get() = delegate.constructor
|
||||||
|
override val arguments: List<TypeProjection> get() = delegate.arguments
|
||||||
|
override val isMarkedNullable: Boolean get() = delegate.isMarkedNullable
|
||||||
|
override val memberScope: MemberScope get() = delegate.memberScope
|
||||||
|
override val isError: Boolean get() = false
|
||||||
|
|
||||||
|
override fun toString(): String = DescriptorRenderer.DEBUG_TEXT.renderType(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("Temporary marker method for refactoring")
|
||||||
|
fun KotlinType.asSimpleType(): SimpleType {
|
||||||
|
return unwrap() as SimpleType
|
||||||
|
}
|
||||||
|
|||||||
@@ -29,14 +29,14 @@ object KotlinTypeFactory {
|
|||||||
arguments: List<TypeProjection>,
|
arguments: List<TypeProjection>,
|
||||||
nullable: Boolean,
|
nullable: Boolean,
|
||||||
memberScope: MemberScope
|
memberScope: MemberScope
|
||||||
): SimpleType = KotlinTypeImpl.create(annotations, constructor, nullable, arguments, memberScope)
|
): SimpleType = SimpleTypeImpl(annotations, constructor, arguments, nullable, memberScope)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun simpleNotNullType(
|
fun simpleNotNullType(
|
||||||
annotations: Annotations,
|
annotations: Annotations,
|
||||||
descriptor: ClassDescriptor,
|
descriptor: ClassDescriptor,
|
||||||
arguments: List<TypeProjection>
|
arguments: List<TypeProjection>
|
||||||
): SimpleType = KotlinTypeImpl.create(annotations, descriptor.typeConstructor, false, arguments, descriptor.getMemberScope(arguments))
|
): SimpleType = SimpleTypeImpl(annotations, descriptor.typeConstructor, arguments, false, descriptor.getMemberScope(arguments))
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun simpleType(
|
fun simpleType(
|
||||||
@@ -49,8 +49,28 @@ object KotlinTypeFactory {
|
|||||||
): SimpleType = simpleType(annotations, constructor, arguments, nullable, memberScope)
|
): SimpleType = simpleType(annotations, constructor, arguments, nullable, memberScope)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun flexibleType(lowerBound: SimpleType, upperBound: SimpleType): KotlinType {
|
fun flexibleType(lowerBound: SimpleType, upperBound: SimpleType): UnwrappedType {
|
||||||
if (lowerBound == upperBound) return lowerBound
|
if (lowerBound == upperBound) return lowerBound
|
||||||
return FlexibleTypeImpl(lowerBound, upperBound)
|
return FlexibleTypeImpl(lowerBound, upperBound)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class SimpleTypeImpl(
|
||||||
|
override val annotations: Annotations,
|
||||||
|
override val constructor: TypeConstructor,
|
||||||
|
override val arguments: List<TypeProjection>,
|
||||||
|
override val isMarkedNullable: Boolean,
|
||||||
|
override val memberScope: MemberScope
|
||||||
|
) : SimpleType() {
|
||||||
|
override fun replaceAnnotations(newAnnotations: Annotations) = SimpleTypeImpl(newAnnotations, constructor, arguments, isMarkedNullable, memberScope)
|
||||||
|
override fun makeNullableAsSpecified(newNullability: Boolean) = SimpleTypeImpl(annotations, constructor, arguments, newNullability, memberScope)
|
||||||
|
|
||||||
|
override val isError: Boolean
|
||||||
|
get() = false
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (memberScope is ErrorUtils.ErrorScope) {
|
||||||
|
throw IllegalStateException("SimpleTypeImpl should not be created for error type: $memberScope\n$constructor")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.types
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
|
||||||
|
|
||||||
open class KotlinTypeImpl
|
|
||||||
internal constructor(
|
|
||||||
override val annotations: Annotations,
|
|
||||||
final override val constructor: TypeConstructor,
|
|
||||||
override val isMarkedNullable: Boolean,
|
|
||||||
override val arguments: List<TypeProjection>,
|
|
||||||
final override val memberScope: MemberScope
|
|
||||||
) : AbstractKotlinType(), SimpleType {
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
@Deprecated("", ReplaceWith("KotlinTypeFactory.simpleType(annotations, constructor, arguments, nullable, memberScope)", "org.jetbrains.kotlin.types.KotlinTypeFactory"))
|
|
||||||
@JvmStatic fun create(annotations: Annotations,
|
|
||||||
constructor: TypeConstructor,
|
|
||||||
nullable: Boolean,
|
|
||||||
arguments: List<TypeProjection>,
|
|
||||||
memberScope: MemberScope): KotlinTypeImpl
|
|
||||||
|
|
||||||
= KotlinTypeImpl(annotations, constructor, nullable, arguments, memberScope)
|
|
||||||
|
|
||||||
@JvmStatic fun create(annotations: Annotations,
|
|
||||||
constructor: TypeConstructor,
|
|
||||||
nullable: Boolean,
|
|
||||||
arguments: List<TypeProjection>,
|
|
||||||
memberScope: MemberScope,
|
|
||||||
abbreviatedType: SimpleType? = null
|
|
||||||
): KotlinTypeImpl {
|
|
||||||
if (abbreviatedType != null) {
|
|
||||||
return WithCapabilities(annotations, constructor, nullable, arguments, memberScope, abbreviatedType)
|
|
||||||
}
|
|
||||||
return KotlinTypeImpl(annotations, constructor, nullable, arguments, memberScope)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated("", ReplaceWith("KotlinTypeFactory.simpleType(annotations, descriptor, arguments, nullable)", "org.jetbrains.kotlin.types.KotlinTypeFactory"))
|
|
||||||
@JvmStatic fun create(annotations: Annotations,
|
|
||||||
descriptor: ClassDescriptor,
|
|
||||||
nullable: Boolean,
|
|
||||||
arguments: List<TypeProjection>): KotlinTypeImpl
|
|
||||||
|
|
||||||
= KotlinTypeImpl(
|
|
||||||
annotations, descriptor.typeConstructor, nullable, arguments, descriptor.getMemberScope(arguments)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private class WithCapabilities(
|
|
||||||
annotations: Annotations,
|
|
||||||
constructor: TypeConstructor,
|
|
||||||
nullable: Boolean,
|
|
||||||
arguments: List<TypeProjection>,
|
|
||||||
memberScope: MemberScope,
|
|
||||||
override val abbreviatedType: SimpleType?
|
|
||||||
) : KotlinTypeImpl(annotations, constructor, nullable, arguments, memberScope)
|
|
||||||
|
|
||||||
init {
|
|
||||||
if (memberScope is ErrorUtils.ErrorScope) {
|
|
||||||
throw IllegalStateException("JetTypeImpl should not be created for error type: $memberScope\n$constructor")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override val isError: Boolean get() = false
|
|
||||||
}
|
|
||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,5 +16,5 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.types;
|
package org.jetbrains.kotlin.types;
|
||||||
|
|
||||||
public interface LazyType extends KotlinType {
|
public interface LazyType {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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.types
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
|
|
||||||
|
abstract class DelegatingSimpleType : SimpleType() {
|
||||||
|
protected abstract val delegate: SimpleType
|
||||||
|
|
||||||
|
override val annotations: Annotations get() = delegate.annotations
|
||||||
|
override val constructor: TypeConstructor get() = delegate.constructor
|
||||||
|
override val arguments: List<TypeProjection> get() = delegate.arguments
|
||||||
|
override val isMarkedNullable: Boolean get() = delegate.isMarkedNullable
|
||||||
|
override val memberScope: MemberScope get() = delegate.memberScope
|
||||||
|
}
|
||||||
|
|
||||||
|
private class AbbreviatedType(override val delegate: SimpleType, val abbreviatedType: SimpleType) : DelegatingSimpleType() {
|
||||||
|
override fun replaceAnnotations(newAnnotations: Annotations)
|
||||||
|
= AbbreviatedType(delegate.replaceAnnotations(newAnnotations), abbreviatedType)
|
||||||
|
|
||||||
|
override fun makeNullableAsSpecified(newNullability: Boolean)
|
||||||
|
= AbbreviatedType(delegate.makeNullableAsSpecified(newNullability), abbreviatedType.makeNullableAsSpecified(newNullability))
|
||||||
|
|
||||||
|
override val isError: Boolean get() = false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun KotlinType.getAbbreviatedType(): SimpleType? = (unwrap() as? AbbreviatedType)?.abbreviatedType
|
||||||
|
|
||||||
|
fun SimpleType.withAbbreviatedType(abbreviatedType: SimpleType): SimpleType {
|
||||||
|
if (isError) return this
|
||||||
|
return AbbreviatedType(this, abbreviatedType)
|
||||||
|
}
|
||||||
@@ -121,11 +121,11 @@ fun KotlinType.replace(
|
|||||||
if (newArguments.isEmpty() && newAnnotations === annotations) return this
|
if (newArguments.isEmpty() && newAnnotations === annotations) return this
|
||||||
|
|
||||||
if (newArguments.isEmpty()) {
|
if (newArguments.isEmpty()) {
|
||||||
return KotlinTypeImpl.create(
|
return KotlinTypeFactory.simpleType(
|
||||||
newAnnotations,
|
newAnnotations,
|
||||||
constructor,
|
constructor,
|
||||||
isMarkedNullable,
|
|
||||||
arguments,
|
arguments,
|
||||||
|
isMarkedNullable,
|
||||||
memberScope
|
memberScope
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -138,11 +138,11 @@ fun KotlinType.replace(
|
|||||||
declarationDescriptor.getMemberScope(newSubstitution)
|
declarationDescriptor.getMemberScope(newSubstitution)
|
||||||
else ErrorUtils.createErrorScope("Unexpected declaration descriptor for type constructor: $constructor")
|
else ErrorUtils.createErrorScope("Unexpected declaration descriptor for type constructor: $constructor")
|
||||||
|
|
||||||
return KotlinTypeImpl.create(
|
return KotlinTypeFactory.simpleType(
|
||||||
newAnnotations,
|
newAnnotations,
|
||||||
constructor,
|
constructor,
|
||||||
isMarkedNullable,
|
|
||||||
newArguments,
|
newArguments,
|
||||||
|
isMarkedNullable,
|
||||||
newScope
|
newScope
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ public class TypeSubstitutor {
|
|||||||
|
|
||||||
// The type is within the substitution range, i.e. T or T?
|
// The type is within the substitution range, i.e. T or T?
|
||||||
KotlinType type = originalProjection.getType();
|
KotlinType type = originalProjection.getType();
|
||||||
if (DynamicTypesKt.isDynamic(type) || KotlinTypeKt.unwrap(type) instanceof RawType) {
|
if (DynamicTypesKt.isDynamic(type) || type.unwrap() instanceof RawType) {
|
||||||
return originalProjection; // todo investigate
|
return originalProjection; // todo investigate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class TypeUtils {
|
|||||||
public static final SimpleType DONT_CARE = ErrorUtils.createErrorTypeWithCustomDebugName("DONT_CARE");
|
public static final SimpleType DONT_CARE = ErrorUtils.createErrorTypeWithCustomDebugName("DONT_CARE");
|
||||||
public static final SimpleType CANT_INFER_FUNCTION_PARAM_TYPE = ErrorUtils.createErrorType("Cannot be inferred");
|
public static final SimpleType CANT_INFER_FUNCTION_PARAM_TYPE = ErrorUtils.createErrorType("Cannot be inferred");
|
||||||
|
|
||||||
public static class SpecialType implements SimpleType {
|
public static class SpecialType extends DelegatingSimpleType {
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
public SpecialType(String name) {
|
public SpecialType(String name) {
|
||||||
@@ -45,24 +45,7 @@ public class TypeUtils {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public TypeConstructor getConstructor() {
|
protected SimpleType getDelegate() {
|
||||||
throw new IllegalStateException(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public List<TypeProjection> getArguments() {
|
|
||||||
throw new IllegalStateException(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isMarkedNullable() {
|
|
||||||
throw new IllegalStateException(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public MemberScope getMemberScope() {
|
|
||||||
throw new IllegalStateException(name);
|
throw new IllegalStateException(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +56,13 @@ public class TypeUtils {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Annotations getAnnotations() {
|
public SimpleType replaceAnnotations(@NotNull Annotations newAnnotations) {
|
||||||
|
throw new IllegalStateException(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public SimpleType makeNullableAsSpecified(boolean newNullability) {
|
||||||
throw new IllegalStateException(name);
|
throw new IllegalStateException(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,12 +70,6 @@ public class TypeUtils {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public SimpleType getAbbreviatedType() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -129,17 +112,7 @@ public class TypeUtils {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static KotlinType makeNullableAsSpecified(@NotNull KotlinType type, boolean nullable) {
|
public static KotlinType makeNullableAsSpecified(@NotNull KotlinType type, boolean nullable) {
|
||||||
KotlinType unwrappedType = KotlinTypeKt.unwrap(type);
|
return type.unwrap().makeNullableAsSpecified(nullable);
|
||||||
if (unwrappedType instanceof TypeWithCustomReplacement) {
|
|
||||||
return ((TypeWithCustomReplacement) unwrappedType).makeNullableAsSpecified(nullable);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
SimpleType simpleType = (SimpleType) unwrappedType;
|
|
||||||
|
|
||||||
if (!(simpleType instanceof LazyType) && simpleType.isMarkedNullable() == nullable) return simpleType;
|
|
||||||
|
|
||||||
return KotlinTypeKt.lazyReplaceNullability(simpleType, nullable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -431,7 +404,7 @@ public class TypeUtils {
|
|||||||
if (type == null) return false;
|
if (type == null) return false;
|
||||||
if (isSpecialType.invoke(type)) return true;
|
if (isSpecialType.invoke(type)) return true;
|
||||||
|
|
||||||
KotlinType unwrappedType = KotlinTypeKt.unwrap(type);
|
UnwrappedType unwrappedType = type.unwrap();
|
||||||
FlexibleType flexibleType = unwrappedType instanceof FlexibleType ? (FlexibleType) unwrappedType : null;
|
FlexibleType flexibleType = unwrappedType instanceof FlexibleType ? (FlexibleType) unwrappedType : null;
|
||||||
if (flexibleType != null
|
if (flexibleType != null
|
||||||
&& (contains(flexibleType.getLowerBound(), isSpecialType) || contains(flexibleType.getUpperBound(), isSpecialType))) {
|
&& (contains(flexibleType.getLowerBound(), isSpecialType) || contains(flexibleType.getUpperBound(), isSpecialType))) {
|
||||||
|
|||||||
@@ -85,10 +85,7 @@ fun TypeProjection.substitute(doSubstitute: (KotlinType) -> KotlinType): TypePro
|
|||||||
|
|
||||||
fun KotlinType.replaceAnnotations(newAnnotations: Annotations): KotlinType {
|
fun KotlinType.replaceAnnotations(newAnnotations: Annotations): KotlinType {
|
||||||
if (annotations.isEmpty() && newAnnotations.isEmpty()) return this
|
if (annotations.isEmpty() && newAnnotations.isEmpty()) return this
|
||||||
val unwrappedType = unwrap()
|
return unwrap().replaceAnnotations(newAnnotations)
|
||||||
if (unwrappedType is TypeWithCustomReplacement) return unwrappedType.replaceAnnotations(newAnnotations)
|
|
||||||
|
|
||||||
return asSimpleType().lazyReplaceAnnotations(newAnnotations)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KotlinTypeChecker.equalTypesOrNulls(type1: KotlinType?, type2: KotlinType?): Boolean {
|
fun KotlinTypeChecker.equalTypesOrNulls(type1: KotlinType?, type2: KotlinType?): Boolean {
|
||||||
@@ -165,7 +162,7 @@ fun KotlinType.replaceArgumentsWithStarProjections(): KotlinType {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return asSimpleType().replaceArgumentsWithStarProjections()
|
return (unwrapped as SimpleType).replaceArgumentsWithStarProjections()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,17 +36,15 @@ 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) : DelegatingFlexibleType(builtIns.nothingType, builtIns.nullableAnyType) {
|
class DynamicType(builtIns: KotlinBuiltIns, override val annotations: Annotations) : FlexibleType(builtIns.nothingType, builtIns.nullableAnyType) {
|
||||||
override val delegateType: KotlinType get() = upperBound
|
override val delegate: SimpleType get() = upperBound
|
||||||
|
|
||||||
override fun makeNullableAsSpecified(nullable: Boolean): KotlinType {
|
// Nullability has no effect on dynamics
|
||||||
// Nullability has no effect on dynamics
|
override fun makeNullableAsSpecified(newNullability: Boolean): DynamicType = this
|
||||||
return createDynamicType(delegateType.builtIns)
|
|
||||||
}
|
|
||||||
|
|
||||||
override val isMarkedNullable: Boolean get() = false
|
override val isMarkedNullable: Boolean get() = false
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations): KotlinType = DynamicType(delegateType.builtIns, annotations)
|
override fun replaceAnnotations(newAnnotations: Annotations): DynamicType = DynamicType(delegate.builtIns, annotations)
|
||||||
|
|
||||||
override fun render(renderer: DescriptorRenderer, options: DescriptorRendererOptions): String = "dynamic"
|
override fun render(renderer: DescriptorRenderer, options: DescriptorRendererOptions): String = "dynamic"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,21 +23,6 @@ import org.jetbrains.kotlin.renderer.DescriptorRendererOptions
|
|||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||||
import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations
|
import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations
|
||||||
|
|
||||||
interface FlexibleType : SubtypingRepresentatives, TypeWithCustomReplacement {
|
|
||||||
// lowerBound is a subtype of upperBound
|
|
||||||
val lowerBound: SimpleType
|
|
||||||
val upperBound: SimpleType
|
|
||||||
|
|
||||||
override val subTypeRepresentative: KotlinType
|
|
||||||
get() = lowerBound
|
|
||||||
|
|
||||||
override val superTypeRepresentative: KotlinType
|
|
||||||
get() = upperBound
|
|
||||||
|
|
||||||
override fun sameTypeConstructor(type: KotlinType) = false
|
|
||||||
|
|
||||||
fun render(renderer: DescriptorRenderer, options: DescriptorRendererOptions): String
|
|
||||||
}
|
|
||||||
|
|
||||||
fun KotlinType.isFlexible(): Boolean = unwrap() is FlexibleType
|
fun KotlinType.isFlexible(): Boolean = unwrap() is FlexibleType
|
||||||
fun KotlinType.asFlexibleType(): FlexibleType = unwrap() as FlexibleType
|
fun KotlinType.asFlexibleType(): FlexibleType = unwrap() as FlexibleType
|
||||||
@@ -84,21 +69,18 @@ fun Collection<TypeProjection>.singleBestRepresentative(): TypeProjection? {
|
|||||||
fun KotlinType.lowerIfFlexible(): SimpleType = (if (this.isFlexible()) this.asFlexibleType().lowerBound else this).asSimpleType()
|
fun KotlinType.lowerIfFlexible(): SimpleType = (if (this.isFlexible()) this.asFlexibleType().lowerBound else this).asSimpleType()
|
||||||
fun KotlinType.upperIfFlexible(): SimpleType = (if (this.isFlexible()) this.asFlexibleType().upperBound else this).asSimpleType()
|
fun KotlinType.upperIfFlexible(): SimpleType = (if (this.isFlexible()) this.asFlexibleType().upperBound else this).asSimpleType()
|
||||||
|
|
||||||
abstract class DelegatingFlexibleType protected constructor(
|
class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : FlexibleType(lowerBound, upperBound), CustomTypeVariable {
|
||||||
override val lowerBound: SimpleType,
|
|
||||||
override val upperBound: SimpleType
|
|
||||||
) : DelegatingType(), FlexibleType {
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField
|
@JvmField
|
||||||
var RUN_SLOW_ASSERTIONS = false
|
var RUN_SLOW_ASSERTIONS = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// These assertions are needed for checking invariants of flexible types.
|
// These assertions are needed for checking invariants of flexible types.
|
||||||
//
|
//
|
||||||
// Unfortunately isSubtypeOf is running resolve for lazy types.
|
// Unfortunately isSubtypeOf is running resolve for lazy types.
|
||||||
// Because of this we can't run these assertions when we are creating this type. See EA-74904
|
// Because of this we can't run these assertions when we are creating this type. See EA-74904
|
||||||
//
|
//
|
||||||
// Also isSubtypeOf is not a very fast operation, so we are running assertions only if ASSERTIONS_ENABLED. See KT-7540
|
// Also isSubtypeOf is not a very fast operation, so we are running assertions only if ASSERTIONS_ENABLED. See KT-7540
|
||||||
private var assertionsDone = false
|
private var assertionsDone = false
|
||||||
|
|
||||||
private fun runAssertions() {
|
private fun runAssertions() {
|
||||||
@@ -113,39 +95,25 @@ abstract class DelegatingFlexibleType protected constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract val delegateType: KotlinType
|
override val delegate: SimpleType
|
||||||
|
get() {
|
||||||
override fun makeNullableAsSpecified(nullable: Boolean): KotlinType {
|
runAssertions()
|
||||||
return KotlinTypeFactory.flexibleType(TypeUtils.makeNullableAsSpecified(lowerBound, nullable), TypeUtils.makeNullableAsSpecified(upperBound, nullable))
|
return lowerBound
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDelegate(): KotlinType {
|
|
||||||
runAssertions()
|
|
||||||
return delegateType
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString() = "('$lowerBound'..'$upperBound')"
|
|
||||||
}
|
|
||||||
|
|
||||||
class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : DelegatingFlexibleType(lowerBound, upperBound), CustomTypeVariable {
|
|
||||||
|
|
||||||
override val delegateType: KotlinType get() = lowerBound
|
|
||||||
|
|
||||||
override val isTypeVariable: Boolean get() = lowerBound.constructor.declarationDescriptor is TypeParameterDescriptor
|
override val isTypeVariable: Boolean get() = lowerBound.constructor.declarationDescriptor is TypeParameterDescriptor
|
||||||
&& lowerBound.constructor == upperBound.constructor
|
&& lowerBound.constructor == upperBound.constructor
|
||||||
|
|
||||||
override fun substitutionResult(replacement: KotlinType): KotlinType {
|
override fun substitutionResult(replacement: KotlinType): KotlinType {
|
||||||
if (replacement.isFlexible()) {
|
val unwrapped = replacement.unwrap()
|
||||||
return replacement
|
return when(unwrapped) {
|
||||||
}
|
is FlexibleType -> unwrapped
|
||||||
else {
|
is SimpleType -> KotlinTypeFactory.flexibleType(unwrapped, TypeUtils.makeNullable(unwrapped))
|
||||||
val simpleType = replacement.asSimpleType()
|
|
||||||
return KotlinTypeFactory.flexibleType(simpleType, TypeUtils.makeNullable(simpleType))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations): KotlinType
|
override fun replaceAnnotations(newAnnotations: Annotations): UnwrappedType
|
||||||
= KotlinTypeFactory.flexibleType(lowerBound.replaceAnnotations(newAnnotations).asSimpleType(), upperBound)
|
= KotlinTypeFactory.flexibleType(lowerBound.replaceAnnotations(newAnnotations), upperBound.replaceAnnotations(newAnnotations))
|
||||||
|
|
||||||
override fun render(renderer: DescriptorRenderer, options: DescriptorRendererOptions): String {
|
override fun render(renderer: DescriptorRenderer, options: DescriptorRendererOptions): String {
|
||||||
if (options.debugMode) {
|
if (options.debugMode) {
|
||||||
@@ -153,4 +121,7 @@ class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : Delegat
|
|||||||
}
|
}
|
||||||
return renderer.renderFlexibleType(renderer.renderType(lowerBound), renderer.renderType(upperBound))
|
return renderer.renderFlexibleType(renderer.renderType(lowerBound), renderer.renderType(upperBound))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun makeNullableAsSpecified(newNullability: Boolean): UnwrappedType
|
||||||
|
= KotlinTypeFactory.flexibleType(lowerBound.makeNullableAsSpecified(newNullability), upperBound.makeNullableAsSpecified(newNullability))
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-4
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.storage.getValue
|
|||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||||
|
|
||||||
class DeserializedType(
|
class DeserializedType private constructor(
|
||||||
private val c: DeserializationContext,
|
private val c: DeserializationContext,
|
||||||
private val typeProto: ProtoBuf.Type,
|
private val typeProto: ProtoBuf.Type,
|
||||||
private val additionalAnnotations: Annotations = Annotations.EMPTY
|
private val additionalAnnotations: Annotations = Annotations.EMPTY
|
||||||
@@ -54,9 +54,18 @@ class DeserializedType(
|
|||||||
return descriptor != null && ErrorUtils.isError(descriptor)
|
return descriptor != null && ErrorUtils.isError(descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val abbreviatedType by c.storageManager.createNullableLazyValue {
|
companion object {
|
||||||
val abbreviatedTypeProto = typeProto.abbreviatedType(c.typeTable) ?: return@createNullableLazyValue null
|
fun create(
|
||||||
|
c: DeserializationContext,
|
||||||
|
typeProto: ProtoBuf.Type,
|
||||||
|
additionalAnnotations: Annotations
|
||||||
|
): SimpleType {
|
||||||
|
val deserializedType = DeserializedType(c, typeProto, additionalAnnotations)
|
||||||
|
val abbreviatedTypeProto = typeProto.abbreviatedType(c.typeTable) ?: return deserializedType
|
||||||
|
|
||||||
c.typeDeserializer.type(abbreviatedTypeProto, additionalAnnotations).asSimpleType()
|
return deserializedType.withAbbreviatedType(DeserializedType(c, abbreviatedTypeProto, additionalAnnotations))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -58,12 +58,12 @@ class TypeDeserializer(
|
|||||||
fun type(proto: ProtoBuf.Type, additionalAnnotations: Annotations = Annotations.EMPTY): KotlinType {
|
fun type(proto: ProtoBuf.Type, additionalAnnotations: Annotations = Annotations.EMPTY): KotlinType {
|
||||||
if (proto.hasFlexibleTypeCapabilitiesId()) {
|
if (proto.hasFlexibleTypeCapabilitiesId()) {
|
||||||
val id = c.nameResolver.getString(proto.flexibleTypeCapabilitiesId)
|
val id = c.nameResolver.getString(proto.flexibleTypeCapabilitiesId)
|
||||||
val lowerBound = DeserializedType(c, proto, additionalAnnotations)
|
val lowerBound = DeserializedType.create(c, proto, additionalAnnotations)
|
||||||
val upperBound = DeserializedType(c, proto.flexibleUpperBound(c.typeTable)!!, additionalAnnotations)
|
val upperBound = DeserializedType.create(c, proto.flexibleUpperBound(c.typeTable)!!, additionalAnnotations)
|
||||||
return c.components.flexibleTypeDeserializer.create(proto, id, lowerBound, upperBound)
|
return c.components.flexibleTypeDeserializer.create(proto, id, lowerBound, upperBound)
|
||||||
}
|
}
|
||||||
|
|
||||||
return DeserializedType(c, proto, additionalAnnotations)
|
return DeserializedType.create(c, proto, additionalAnnotations)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun typeConstructor(proto: ProtoBuf.Type): TypeConstructor =
|
fun typeConstructor(proto: ProtoBuf.Type): TypeConstructor =
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
|||||||
import org.jetbrains.kotlin.types.FlexibleType
|
import org.jetbrains.kotlin.types.FlexibleType
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||||
import org.jetbrains.kotlin.types.unwrap
|
|
||||||
|
|
||||||
fun KtFunctionLiteral.findLabelAndCall(): Pair<Name?, KtCallExpression?> {
|
fun KtFunctionLiteral.findLabelAndCall(): Pair<Name?, KtCallExpression?> {
|
||||||
val literalParent = (this.parent as KtLambdaExpression).parent
|
val literalParent = (this.parent as KtLambdaExpression).parent
|
||||||
|
|||||||
+1
-2
@@ -89,8 +89,7 @@ private object ForceTypeCopySubstitution : TypeSubstitution() {
|
|||||||
override fun get(key: KotlinType) =
|
override fun get(key: KotlinType) =
|
||||||
with(key) {
|
with(key) {
|
||||||
if (isError) return@with asTypeProjection()
|
if (isError) return@with asTypeProjection()
|
||||||
KotlinTypeImpl.create(
|
KotlinTypeFactory.simpleType(annotations, constructor, arguments, isMarkedNullable, memberScope).asTypeProjection()
|
||||||
annotations, constructor, isMarkedNullable, arguments, memberScope).asTypeProjection()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isEmpty() = false
|
override fun isEmpty() = false
|
||||||
|
|||||||
+2
-2
@@ -20,10 +20,10 @@ import com.google.protobuf.ExtensionRegistryLite
|
|||||||
import org.jetbrains.kotlin.serialization.KotlinSerializerExtensionBase
|
import org.jetbrains.kotlin.serialization.KotlinSerializerExtensionBase
|
||||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||||
import org.jetbrains.kotlin.serialization.SerializerExtensionProtocol
|
import org.jetbrains.kotlin.serialization.SerializerExtensionProtocol
|
||||||
import org.jetbrains.kotlin.types.DelegatingFlexibleType
|
import org.jetbrains.kotlin.types.FlexibleType
|
||||||
|
|
||||||
class KotlinJavascriptSerializerExtension : KotlinSerializerExtensionBase(JsSerializerProtocol) {
|
class KotlinJavascriptSerializerExtension : KotlinSerializerExtensionBase(JsSerializerProtocol) {
|
||||||
override fun serializeFlexibleType(flexibleType: DelegatingFlexibleType, lowerProto: ProtoBuf.Type.Builder, upperProto: ProtoBuf.Type.Builder) {
|
override fun serializeFlexibleType(flexibleType: FlexibleType, lowerProto: ProtoBuf.Type.Builder, upperProto: ProtoBuf.Type.Builder) {
|
||||||
lowerProto.flexibleTypeCapabilitiesId = stringTable.getStringIndex(DynamicTypeDeserializer.id)
|
lowerProto.flexibleTypeCapabilitiesId = stringTable.getStringIndex(DynamicTypeDeserializer.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user