Remove type capability CustomTypeVariable.
This commit is contained in:
+20
-22
@@ -124,12 +124,6 @@ private fun KotlinType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers
|
||||
|
||||
val newSubstitution = TypeConstructorSubstitution.create(typeConstructor, enhancedArguments)
|
||||
|
||||
val newCapabilities =
|
||||
if (effectiveQualifiers.isNotNullTypeParameter)
|
||||
capabilities.addCapability(CustomTypeVariable::class.java, NotNullTypeParameterTypeCapability)
|
||||
else
|
||||
capabilities
|
||||
|
||||
val enhancedType = KotlinTypeImpl.create(
|
||||
newAnnotations,
|
||||
typeConstructor,
|
||||
@@ -137,10 +131,11 @@ private fun KotlinType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers
|
||||
enhancedArguments,
|
||||
if (enhancedClassifier is ClassDescriptor)
|
||||
enhancedClassifier.getMemberScope(newSubstitution)
|
||||
else enhancedClassifier.getDefaultType().memberScope,
|
||||
newCapabilities
|
||||
else enhancedClassifier.getDefaultType().memberScope
|
||||
)
|
||||
return Result(enhancedType, subtreeSize, wereChanges = true)
|
||||
|
||||
val result = if (effectiveQualifiers.isNotNullTypeParameter) NotNullTypeParameter(enhancedType) else enhancedType
|
||||
return Result(result, subtreeSize, wereChanges = true)
|
||||
}
|
||||
|
||||
private fun List<Annotations>.compositeAnnotationsOrSingle() = when (size) {
|
||||
@@ -218,28 +213,31 @@ private object EnhancedTypeAnnotationDescriptor : AnnotationDescriptor {
|
||||
override fun toString() = "[EnhancedType]"
|
||||
}
|
||||
|
||||
internal object NotNullTypeParameterTypeCapability : CustomTypeVariable {
|
||||
internal class NotNullTypeParameter(private val delegate: SimpleType) : CustomTypeVariable, DelegatingType(), SimpleType {
|
||||
override fun getDelegate(): KotlinType? = delegate
|
||||
|
||||
override val isTypeVariable: Boolean
|
||||
get() = true
|
||||
|
||||
override fun substitutionResult(replacement: KotlinType): KotlinType {
|
||||
if (!TypeUtils.isNullableType(replacement) && !replacement.isTypeParameter()) return replacement
|
||||
val unwrappedType = replacement.unwrap()
|
||||
if (!TypeUtils.isNullableType(unwrappedType) && !unwrappedType.isTypeParameter()) return unwrappedType
|
||||
|
||||
if (replacement.isFlexible()) {
|
||||
with(replacement.asFlexibleType()) {
|
||||
return KotlinTypeFactory.flexibleType(lowerBound.prepareReplacement().asSimpleType(), upperBound.prepareReplacement().asSimpleType())
|
||||
}
|
||||
return when (unwrappedType) {
|
||||
is SimpleType -> unwrappedType.prepareReplacement()
|
||||
is FlexibleType -> KotlinTypeFactory.flexibleType(unwrappedType.lowerBound.prepareReplacement(),
|
||||
unwrappedType.upperBound.prepareReplacement())
|
||||
else -> error("Incorrect type: $unwrappedType")
|
||||
}
|
||||
|
||||
return replacement.prepareReplacement()
|
||||
}
|
||||
|
||||
private fun KotlinType.prepareReplacement(): KotlinType {
|
||||
val result = makeNotNullable()
|
||||
override val isMarkedNullable: Boolean
|
||||
get() = false
|
||||
|
||||
private fun SimpleType.prepareReplacement(): SimpleType {
|
||||
val result = TypeUtils.makeNullableAsSpecified(this, false)
|
||||
if (!this.isTypeParameter()) return result
|
||||
|
||||
return result.replace(
|
||||
newCapabilities = capabilities.addCapability(
|
||||
CustomTypeVariable::class.java, NotNullTypeParameterTypeCapability))
|
||||
return NotNullTypeParameter(result)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ private fun KotlinType.extractQualifiers(): JavaTypeQualifiers {
|
||||
return JavaTypeQualifiers(
|
||||
if (lower.isMarkedNullable) NULLABLE else if (!upper.isMarkedNullable) NOT_NULL else null,
|
||||
if (mapping.isReadOnly(lower)) READ_ONLY else if (mapping.isMutable(upper)) MUTABLE else null,
|
||||
isNotNullTypeParameter = getCapability<CustomTypeVariable>() is NotNullTypeParameterTypeCapability)
|
||||
isNotNullTypeParameter = unwrap() is NotNullTypeParameter)
|
||||
}
|
||||
|
||||
private fun KotlinType.extractQualifiersFromAnnotations(): JavaTypeQualifiers {
|
||||
|
||||
@@ -133,6 +133,7 @@ private class WrappedSimpleType(
|
||||
|
||||
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, capabilities, abbreviatedType)
|
||||
}
|
||||
|
||||
|
||||
@@ -53,16 +53,16 @@ inline fun <reified T : TypeCapability> KotlinType.getCapability(): T? = getCapa
|
||||
// To facilitate laziness, any KotlinType implementation may inherit from this trait,
|
||||
// even if it turns out that the type an instance represents is not actually a type variable
|
||||
// (i.e. it is not derived from a type parameter), see isTypeVariable
|
||||
interface CustomTypeVariable : TypeCapability {
|
||||
interface CustomTypeVariable {
|
||||
val isTypeVariable: Boolean
|
||||
|
||||
// Throws an exception when isTypeVariable == false
|
||||
fun substitutionResult(replacement: KotlinType): KotlinType
|
||||
}
|
||||
|
||||
fun KotlinType.isCustomTypeVariable(): Boolean = this.getCapability(CustomTypeVariable::class.java)?.isTypeVariable ?: false
|
||||
fun KotlinType.isCustomTypeVariable(): Boolean = (unwrap() as? CustomTypeVariable)?.isTypeVariable ?: false
|
||||
fun KotlinType.getCustomTypeVariable(): CustomTypeVariable? =
|
||||
this.getCapability(CustomTypeVariable::class.java)?.let {
|
||||
(unwrap() as? CustomTypeVariable)?.let {
|
||||
if (it.isTypeVariable) it else null
|
||||
}
|
||||
|
||||
|
||||
@@ -132,9 +132,6 @@ class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : Delegat
|
||||
override val delegateType: KotlinType get() = lowerBound
|
||||
|
||||
override fun <T : TypeCapability> getCapability(capabilityClass: Class<T>): T? {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
if (capabilityClass == CustomTypeVariable::class.java) return this as T
|
||||
|
||||
return super.getCapability(capabilityClass)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user