Refine naming: *TypeVariable -> *TypeParameter

This commit is contained in:
Denis.Zharkov
2021-09-30 10:50:21 +03:00
committed by TeamCityServer
parent 7c3383bb39
commit 4733a0d970
13 changed files with 39 additions and 43 deletions
@@ -93,7 +93,7 @@ class LazyWrappedType(
class DefinitelyNotNullType private constructor(
val original: SimpleType,
private val useCorrectedNullabilityForTypeParameters: Boolean
) : DelegatingSimpleType(), CustomTypeVariable,
) : DelegatingSimpleType(), CustomTypeParameter,
DefinitelyNotNullTypeMarker {
companion object {
@@ -161,7 +161,7 @@ class DefinitelyNotNullType private constructor(
override val isMarkedNullable: Boolean
get() = false
override val isTypeVariable: Boolean
override val isTypeParameter: Boolean
get() = delegate.constructor is NewTypeVariableConstructor ||
delegate.constructor.declarationDescriptor is TypeParameterDescriptor
@@ -18,24 +18,24 @@ package org.jetbrains.kotlin.types
// 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 {
val isTypeVariable: Boolean
// even if it turns out that the type an instance represents is not actually a type parameter
// (i.e. it is not derived from a type parameter), see isTypeParameter
interface CustomTypeParameter {
val isTypeParameter: Boolean
// Throws an exception when isTypeVariable == false
// Throws an exception when isTypeParameter == false
fun substitutionResult(replacement: KotlinType): KotlinType
}
// That interface is needed to provide information about definitely not null
// type parameters (e.g. from @NotNull annotation) to type system
interface NotNullTypeVariable : CustomTypeVariable
interface NotNullTypeParameter : CustomTypeParameter
fun KotlinType.isCustomTypeVariable(): Boolean = (unwrap() as? CustomTypeVariable)?.isTypeVariable ?: false
fun KotlinType.getCustomTypeVariable(): CustomTypeVariable? =
(unwrap() as? CustomTypeVariable)?.let {
if (it.isTypeVariable) it else null
}
fun KotlinType.isCustomTypeParameter(): Boolean = (unwrap() as? CustomTypeParameter)?.isTypeParameter ?: false
fun KotlinType.getCustomTypeParameter(): CustomTypeParameter? =
(unwrap() as? CustomTypeParameter)?.let {
if (it.isTypeParameter) it else null
}
interface SubtypingRepresentatives {
val subTypeRepresentative: KotlinType
@@ -45,13 +45,13 @@ interface SubtypingRepresentatives {
}
fun KotlinType.getSubtypeRepresentative(): KotlinType =
(unwrap() as? SubtypingRepresentatives)?.subTypeRepresentative ?: this
(unwrap() as? SubtypingRepresentatives)?.subTypeRepresentative ?: this
fun KotlinType.getSupertypeRepresentative(): KotlinType =
(unwrap() as? SubtypingRepresentatives)?.superTypeRepresentative ?: this
(unwrap() as? SubtypingRepresentatives)?.superTypeRepresentative ?: this
fun sameTypeConstructors(first: KotlinType, second: KotlinType): Boolean {
return (first.unwrap() as? SubtypingRepresentatives)?.sameTypeConstructor(second) ?: false
|| (second.unwrap() as? SubtypingRepresentatives)?.sameTypeConstructor(first) ?: false
|| (second.unwrap() as? SubtypingRepresentatives)?.sameTypeConstructor(first) ?: false
}
@@ -208,7 +208,7 @@ public class TypeSubstitutor implements TypeSubstitutorMarker {
null;
Variance originalProjectionKind = originalProjection.getProjectionKind();
if (replacement == null && FlexibleTypesKt.isFlexible(type) && !TypeCapabilitiesKt.isCustomTypeVariable(type)) {
if (replacement == null && FlexibleTypesKt.isFlexible(type) && !TypeCapabilitiesKt.isCustomTypeParameter(type)) {
FlexibleType flexibleType = FlexibleTypesKt.asFlexibleType(type);
TypeProjection substitutedLower =
unsafeSubstitute(
@@ -255,12 +255,12 @@ public class TypeSubstitutor implements TypeSubstitutorMarker {
}
}
KotlinType substitutedType;
CustomTypeVariable typeVariable = TypeCapabilitiesKt.getCustomTypeVariable(type);
CustomTypeParameter customTypeParameter = TypeCapabilitiesKt.getCustomTypeParameter(type);
if (replacement.isStarProjection()) {
return replacement;
}
else if (typeVariable != null) {
substitutedType = typeVariable.substitutionResult(replacement.getType());
else if (customTypeParameter != null) {
substitutedType = customTypeParameter.substitutionResult(replacement.getType());
}
else {
// this is a simple type T or T?: if it's T, we should just take replacement, if T? - we make replacement nullable
@@ -151,7 +151,7 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
}
@OptIn(ObsoleteTypeKind::class)
override fun KotlinTypeMarker.isNotNullTypeVariable(): Boolean = this is NotNullTypeVariable
override fun KotlinTypeMarker.isNotNullTypeParameter(): Boolean = this is NotNullTypeParameter
override fun SimpleTypeMarker.isMarkedNullable(): Boolean {
require(this is SimpleType, this::errorMessage)
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.types.checker.ErrorTypesAreEqualToAnything
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
import org.jetbrains.kotlin.types.TypeRefinement
import org.jetbrains.kotlin.types.typeUtil.builtIns
fun KotlinType.isFlexible(): Boolean = unwrap() is FlexibleType
@@ -82,7 +81,7 @@ fun KotlinType.upperIfFlexible(): SimpleType = with(unwrap()) {
}
}
class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : FlexibleType(lowerBound, upperBound), CustomTypeVariable {
class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : FlexibleType(lowerBound, upperBound), CustomTypeParameter {
companion object {
@JvmField
var RUN_SLOW_ASSERTIONS = false
@@ -114,7 +113,7 @@ class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : Flexibl
return lowerBound
}
override val isTypeVariable: Boolean
override val isTypeParameter: Boolean
get() = lowerBound.constructor.declarationDescriptor is TypeParameterDescriptor
&& lowerBound.constructor == upperBound.constructor