Refactoring. Minor refactoring and cleanup in FlexibleTypes.
This commit is contained in:
+9
-8
@@ -294,18 +294,19 @@ class LazyJavaTypeResolver(
|
||||
}
|
||||
|
||||
private class Impl(lowerBound: KotlinType, upperBound: KotlinType) :
|
||||
DelegatingFlexibleType(lowerBound, upperBound, FlexibleJavaClassifierTypeFactory), CustomTypeVariable, Specificity {
|
||||
DelegatingFlexibleType(lowerBound, upperBound, FlexibleJavaClassifierTypeFactory), CustomTypeVariable {
|
||||
|
||||
override val delegateType: KotlinType get() = lowerBound
|
||||
|
||||
override fun <T : TypeCapability> getCapability(capabilityClass: Class<T>): T? {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return when (capabilityClass) {
|
||||
CustomTypeVariable::class.java, Specificity::class.java -> this as T
|
||||
else -> super.getCapability(capabilityClass)
|
||||
}
|
||||
if (capabilityClass == CustomTypeVariable::class.java) return this as T
|
||||
|
||||
return super.getCapability(capabilityClass)
|
||||
}
|
||||
|
||||
override val isTypeVariable: Boolean = lowerBound.getConstructor() == upperBound.getConstructor()
|
||||
&& lowerBound.getConstructor().getDeclarationDescriptor() is TypeParameterDescriptor
|
||||
override val isTypeVariable: Boolean = lowerBound.constructor == upperBound.constructor
|
||||
&& lowerBound.constructor.declarationDescriptor is TypeParameterDescriptor
|
||||
|
||||
override fun substitutionResult(replacement: KotlinType): KotlinType {
|
||||
return if (replacement.isFlexible()) replacement
|
||||
@@ -323,7 +324,7 @@ class LazyJavaTypeResolver(
|
||||
// Int! >< Int?
|
||||
if (otherType.isFlexible()) return Specificity.Relation.DONT_KNOW
|
||||
// Int? >< Int!
|
||||
if (otherType.isMarkedNullable()) return Specificity.Relation.DONT_KNOW
|
||||
if (otherType.isMarkedNullable) return Specificity.Relation.DONT_KNOW
|
||||
// Int! lessSpecific Int
|
||||
return Specificity.Relation.LESS_SPECIFIC
|
||||
}
|
||||
|
||||
@@ -43,19 +43,12 @@ object DynamicTypeFactory : FlexibleTypeFactory {
|
||||
return Impl(lowerBound, upperBound)
|
||||
}
|
||||
|
||||
private class Impl(lowerBound: KotlinType, upperBound: KotlinType) : DelegatingFlexibleType(lowerBound, upperBound, DynamicTypeFactory), Dynamicity, Specificity, NullAwareness, FlexibleTypeDelegation {
|
||||
companion object {
|
||||
internal val capabilityClasses = hashSetOf(
|
||||
Dynamicity::class.java,
|
||||
Specificity::class.java,
|
||||
NullAwareness::class.java,
|
||||
FlexibleTypeDelegation::class.java
|
||||
)
|
||||
}
|
||||
private class Impl(lowerBound: KotlinType, upperBound: KotlinType) :
|
||||
DelegatingFlexibleType(lowerBound, upperBound, DynamicTypeFactory), Dynamicity {
|
||||
|
||||
override fun <T : TypeCapability> getCapability(capabilityClass: Class<T>): T? {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
if (capabilityClass in capabilityClasses) return this as T
|
||||
if (capabilityClass == Dynamicity::class.java) return this as T
|
||||
|
||||
return super.getCapability(capabilityClass)
|
||||
}
|
||||
@@ -71,6 +64,6 @@ object DynamicTypeFactory : FlexibleTypeFactory {
|
||||
return createDynamicType(delegateType.builtIns)
|
||||
}
|
||||
|
||||
override fun computeIsNullable() = false
|
||||
override fun isMarkedNullable() = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,24 +87,19 @@ fun KotlinType.upperIfFlexible(): KotlinType = if (this.isFlexible()) this.flexi
|
||||
|
||||
interface NullAwareness : TypeCapability {
|
||||
fun makeNullableAsSpecified(nullable: Boolean): KotlinType
|
||||
fun computeIsNullable(): Boolean
|
||||
}
|
||||
|
||||
interface FlexibleTypeDelegation : TypeCapability {
|
||||
val delegateType: KotlinType
|
||||
}
|
||||
|
||||
open class DelegatingFlexibleType protected constructor(
|
||||
abstract class DelegatingFlexibleType protected constructor(
|
||||
override val lowerBound: KotlinType,
|
||||
override val upperBound: KotlinType,
|
||||
override val factory: FlexibleTypeFactory
|
||||
) : DelegatingType(), NullAwareness, Flexibility, FlexibleTypeDelegation {
|
||||
) : DelegatingType(), NullAwareness, Flexibility, Specificity {
|
||||
companion object {
|
||||
internal val capabilityClasses = hashSetOf(
|
||||
NullAwareness::class.java,
|
||||
Flexibility::class.java,
|
||||
SubtypingRepresentatives::class.java,
|
||||
FlexibleTypeDelegation::class.java
|
||||
Specificity::class.java
|
||||
)
|
||||
|
||||
@JvmField
|
||||
@@ -131,6 +126,8 @@ open class DelegatingFlexibleType protected constructor(
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract val delegateType: KotlinType
|
||||
|
||||
override fun <T : TypeCapability> getCapability(capabilityClass: Class<T>): T? {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
if (capabilityClass in capabilityClasses) return this as T
|
||||
@@ -143,17 +140,10 @@ open class DelegatingFlexibleType protected constructor(
|
||||
TypeUtils.makeNullableAsSpecified(upperBound, nullable))
|
||||
}
|
||||
|
||||
override fun computeIsNullable() = delegateType.isMarkedNullable
|
||||
|
||||
override fun isMarkedNullable(): Boolean = getCapability(NullAwareness::class.java)!!.computeIsNullable()
|
||||
|
||||
override val delegateType: KotlinType
|
||||
get() {
|
||||
runAssertions()
|
||||
return lowerBound
|
||||
}
|
||||
|
||||
override fun getDelegate() = getCapability(FlexibleTypeDelegation::class.java)!!.delegateType
|
||||
final override fun getDelegate(): KotlinType {
|
||||
runAssertions()
|
||||
return delegateType
|
||||
}
|
||||
|
||||
override fun toString() = "('$lowerBound'..'$upperBound')"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user