Minor. remove several methods from TypeUtils
This commit is contained in:
@@ -27,9 +27,9 @@ import org.jetbrains.kotlin.resolve.MemberComparator
|
|||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.TypeUtils
|
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||||
import org.jetbrains.kotlin.types.isDynamic
|
import org.jetbrains.kotlin.types.isDynamic
|
||||||
|
import org.jetbrains.kotlin.types.typeUtil.makeNullable
|
||||||
import org.jetbrains.kotlin.utils.keysToMapExceptNulls
|
import org.jetbrains.kotlin.utils.keysToMapExceptNulls
|
||||||
|
|
||||||
object CodegenUtil {
|
object CodegenUtil {
|
||||||
@@ -156,7 +156,7 @@ object CodegenUtil {
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun isEnumValueOfMethod(functionDescriptor: FunctionDescriptor): Boolean {
|
fun isEnumValueOfMethod(functionDescriptor: FunctionDescriptor): Boolean {
|
||||||
val methodTypeParameters = functionDescriptor.valueParameters
|
val methodTypeParameters = functionDescriptor.valueParameters
|
||||||
val nullableString = TypeUtils.makeNullable(functionDescriptor.builtIns.stringType)
|
val nullableString = functionDescriptor.builtIns.stringType.makeNullable()
|
||||||
return DescriptorUtils.ENUM_VALUE_OF == functionDescriptor.name
|
return DescriptorUtils.ENUM_VALUE_OF == functionDescriptor.name
|
||||||
&& methodTypeParameters.size == 1
|
&& methodTypeParameters.size == 1
|
||||||
&& KotlinTypeChecker.DEFAULT.isSubtypeOf(methodTypeParameters[0].type, nullableString)
|
&& KotlinTypeChecker.DEFAULT.isSubtypeOf(methodTypeParameters[0].type, nullableString)
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ import org.jetbrains.kotlin.codegen.generateIsCheck
|
|||||||
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods
|
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods
|
||||||
import org.jetbrains.kotlin.codegen.optimization.common.intConstant
|
import org.jetbrains.kotlin.codegen.optimization.common.intConstant
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||||
import org.jetbrains.kotlin.types.typeUtil.makeNullableIfNeeded
|
|
||||||
import org.jetbrains.org.objectweb.asm.MethodVisitor
|
import org.jetbrains.org.objectweb.asm.MethodVisitor
|
||||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
@@ -43,7 +43,7 @@ class ReificationArgument(
|
|||||||
)
|
)
|
||||||
|
|
||||||
fun reify(replacementAsmType: Type, kotlinType: KotlinType) =
|
fun reify(replacementAsmType: Type, kotlinType: KotlinType) =
|
||||||
Pair(Type.getType("[".repeat(arrayDepth) + replacementAsmType), kotlinType.arrayOf(arrayDepth).makeNullableIfNeeded(nullable))
|
Pair(Type.getType("[".repeat(arrayDepth) + replacementAsmType), TypeUtils.makeNullableIfNeeded(kotlinType.arrayOf(arrayDepth), nullable))
|
||||||
|
|
||||||
private fun KotlinType.arrayOf(arrayDepth: Int): KotlinType {
|
private fun KotlinType.arrayOf(arrayDepth: Int): KotlinType {
|
||||||
val builtins = this.builtIns
|
val builtins = this.builtIns
|
||||||
|
|||||||
+1
-1
@@ -73,7 +73,7 @@ public class SingleAbstractMethodUtils {
|
|||||||
|
|
||||||
if (FlexibleTypesKt.isNullabilityFlexible(samType)) {
|
if (FlexibleTypesKt.isNullabilityFlexible(samType)) {
|
||||||
SimpleType simpleType = KotlinTypeKt.asSimpleType(type);
|
SimpleType simpleType = KotlinTypeKt.asSimpleType(type);
|
||||||
return KotlinTypeFactory.flexibleType(simpleType, TypeUtils.makeNullable(simpleType));
|
return KotlinTypeFactory.flexibleType(simpleType, simpleType.makeNullableAsSpecified(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
return TypeUtils.makeNullableAsSpecified(type, samType.isMarkedNullable());
|
return TypeUtils.makeNullableAsSpecified(type, samType.isMarkedNullable());
|
||||||
|
|||||||
+2
-2
@@ -103,7 +103,7 @@ object NonExpansiveInheritanceRestrictionChecker {
|
|||||||
val constituents = constituentTypes(setOf(typeProjection.type))
|
val constituents = constituentTypes(setOf(typeProjection.type))
|
||||||
|
|
||||||
for (typeParameter in typeParameters) {
|
for (typeParameter in typeParameters) {
|
||||||
if (typeParameter.defaultType in constituents || TypeUtils.makeNullable(typeParameter.defaultType) in constituents) {
|
if (typeParameter.defaultType in constituents || typeParameter.defaultType.makeNullableAsSpecified(true) in constituents) {
|
||||||
addEdge(typeParameter, constituentTypeConstructor.parameters[i], !TypeUtils.isTypeParameter(typeProjection.type))
|
addEdge(typeParameter, constituentTypeConstructor.parameters[i], !TypeUtils.isTypeParameter(typeProjection.type))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ object NonExpansiveInheritanceRestrictionChecker {
|
|||||||
val boundClosure = boundClosure(bounds)
|
val boundClosure = boundClosure(bounds)
|
||||||
val constituentTypes = constituentTypes(boundClosure)
|
val constituentTypes = constituentTypes(boundClosure)
|
||||||
for (typeParameter in typeParameters) {
|
for (typeParameter in typeParameters) {
|
||||||
if (typeParameter.defaultType in constituentTypes || TypeUtils.makeNullable(typeParameter.defaultType) in constituentTypes) {
|
if (typeParameter.defaultType in constituentTypes || typeParameter.defaultType.makeNullableAsSpecified(true) in constituentTypes) {
|
||||||
addEdge(typeParameter, originalTypeParameter, true)
|
addEdge(typeParameter, originalTypeParameter, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-5
@@ -35,7 +35,6 @@ import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
|
|||||||
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.createProjection
|
import org.jetbrains.kotlin.types.typeUtil.createProjection
|
||||||
import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations
|
|
||||||
import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections
|
import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections
|
||||||
import org.jetbrains.kotlin.utils.sure
|
import org.jetbrains.kotlin.utils.sure
|
||||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||||
@@ -90,8 +89,8 @@ class LazyJavaTypeResolver(
|
|||||||
if (primitiveType != null) {
|
if (primitiveType != null) {
|
||||||
val jetType = c.module.builtIns.getPrimitiveArrayKotlinType(primitiveType)
|
val jetType = c.module.builtIns.getPrimitiveArrayKotlinType(primitiveType)
|
||||||
return@run if (attr.allowFlexible)
|
return@run if (attr.allowFlexible)
|
||||||
KotlinTypeFactory.flexibleType(jetType, TypeUtils.makeNullable(jetType))
|
KotlinTypeFactory.flexibleType(jetType, jetType.makeNullableAsSpecified(true))
|
||||||
else TypeUtils.makeNullableAsSpecified(jetType, !attr.isMarkedNotNull)
|
else jetType.makeNullableAsSpecified(!attr.isMarkedNotNull)
|
||||||
}
|
}
|
||||||
|
|
||||||
val componentType = transformJavaType(javaComponentType,
|
val componentType = transformJavaType(javaComponentType,
|
||||||
@@ -100,12 +99,12 @@ class LazyJavaTypeResolver(
|
|||||||
if (attr.allowFlexible) {
|
if (attr.allowFlexible) {
|
||||||
return@run KotlinTypeFactory.flexibleType(
|
return@run KotlinTypeFactory.flexibleType(
|
||||||
c.module.builtIns.getArrayType(INVARIANT, componentType),
|
c.module.builtIns.getArrayType(INVARIANT, componentType),
|
||||||
TypeUtils.makeNullable(c.module.builtIns.getArrayType(OUT_VARIANCE, componentType)))
|
c.module.builtIns.getArrayType(OUT_VARIANCE, componentType).makeNullableAsSpecified(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
val projectionKind = if (attr.howThisTypeIsUsed == MEMBER_SIGNATURE_CONTRAVARIANT || isVararg) OUT_VARIANCE else INVARIANT
|
val projectionKind = if (attr.howThisTypeIsUsed == MEMBER_SIGNATURE_CONTRAVARIANT || isVararg) OUT_VARIANCE else INVARIANT
|
||||||
val result = c.module.builtIns.getArrayType(projectionKind, componentType)
|
val result = c.module.builtIns.getArrayType(projectionKind, componentType)
|
||||||
return@run TypeUtils.makeNullableAsSpecified(result, !attr.isMarkedNotNull)
|
return@run result.makeNullableAsSpecified(!attr.isMarkedNotNull)
|
||||||
}.replaceAnnotations(attr.typeAnnotations)
|
}.replaceAnnotations(attr.typeAnnotations)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -235,7 +235,7 @@ internal class NotNullTypeParameter(override val delegate: SimpleType) : CustomT
|
|||||||
get() = false
|
get() = false
|
||||||
|
|
||||||
private fun SimpleType.prepareReplacement(): SimpleType {
|
private fun SimpleType.prepareReplacement(): SimpleType {
|
||||||
val result = TypeUtils.makeNullableAsSpecified(this, false)
|
val result = makeNullableAsSpecified(false)
|
||||||
if (!this.isTypeParameter()) return result
|
if (!this.isTypeParameter()) return result
|
||||||
|
|
||||||
return NotNullTypeParameter(result)
|
return NotNullTypeParameter(result)
|
||||||
|
|||||||
@@ -612,7 +612,7 @@ public abstract class KotlinBuiltIns {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public SimpleType getNullableNothingType() {
|
public SimpleType getNullableNothingType() {
|
||||||
return TypeUtils.makeNullable(getNothingType());
|
return getNothingType().makeNullableAsSpecified(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -622,7 +622,7 @@ public abstract class KotlinBuiltIns {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public SimpleType getNullableAnyType() {
|
public SimpleType getNullableAnyType() {
|
||||||
return TypeUtils.makeNullable(getAnyType());
|
return getAnyType().makeNullableAsSpecified(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -95,21 +95,6 @@ public class TypeUtils {
|
|||||||
return makeNullableAsSpecified(type, false);
|
return makeNullableAsSpecified(type, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static SimpleType makeNullable(@NotNull SimpleType type) {
|
|
||||||
return KotlinTypeKt.asSimpleType(makeNullableAsSpecified(type, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static SimpleType makeNotNullable(@NotNull SimpleType type) {
|
|
||||||
return KotlinTypeKt.asSimpleType(makeNullableAsSpecified(type, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static SimpleType makeNullableAsSpecified(@NotNull SimpleType type, boolean nullable) {
|
|
||||||
return KotlinTypeKt.asSimpleType(makeNullableAsSpecified((KotlinType) type, nullable));
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static KotlinType makeNullableAsSpecified(@NotNull KotlinType type, boolean nullable) {
|
public static KotlinType makeNullableAsSpecified(@NotNull KotlinType type, boolean nullable) {
|
||||||
return type.unwrap().makeNullableAsSpecified(nullable);
|
return type.unwrap().makeNullableAsSpecified(nullable);
|
||||||
@@ -117,7 +102,10 @@ public class TypeUtils {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static SimpleType makeNullableIfNeeded(@NotNull SimpleType type, boolean nullable) {
|
public static SimpleType makeNullableIfNeeded(@NotNull SimpleType type, boolean nullable) {
|
||||||
return KotlinTypeKt.asSimpleType(makeNullableIfNeeded((KotlinType) type, nullable));
|
if (nullable) {
|
||||||
|
return type.makeNullableAsSpecified(true);
|
||||||
|
}
|
||||||
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ val KotlinType.builtIns: KotlinBuiltIns
|
|||||||
get() = constructor.builtIns
|
get() = constructor.builtIns
|
||||||
|
|
||||||
fun KotlinType.makeNullable() = TypeUtils.makeNullable(this)
|
fun KotlinType.makeNullable() = TypeUtils.makeNullable(this)
|
||||||
fun KotlinType.makeNullableIfNeeded(nullable: Boolean) = TypeUtils.makeNullableIfNeeded(this, nullable)
|
|
||||||
fun KotlinType.makeNotNullable() = TypeUtils.makeNotNullable(this)
|
fun KotlinType.makeNotNullable() = TypeUtils.makeNotNullable(this)
|
||||||
|
|
||||||
fun KotlinType.immediateSupertypes(): Collection<KotlinType> = TypeUtils.getImmediateSupertypes(this)
|
fun KotlinType.immediateSupertypes(): Collection<KotlinType> = TypeUtils.getImmediateSupertypes(this)
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
|||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions
|
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||||
import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations
|
|
||||||
|
|
||||||
|
|
||||||
fun KotlinType.isFlexible(): Boolean = unwrap() is FlexibleType
|
fun KotlinType.isFlexible(): Boolean = unwrap() is FlexibleType
|
||||||
@@ -117,7 +116,7 @@ class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : Flexibl
|
|||||||
val unwrapped = replacement.unwrap()
|
val unwrapped = replacement.unwrap()
|
||||||
return when(unwrapped) {
|
return when(unwrapped) {
|
||||||
is FlexibleType -> unwrapped
|
is FlexibleType -> unwrapped
|
||||||
is SimpleType -> KotlinTypeFactory.flexibleType(unwrapped, TypeUtils.makeNullable(unwrapped))
|
is SimpleType -> KotlinTypeFactory.flexibleType(unwrapped, unwrapped.makeNullableAsSpecified(true))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,16 +48,16 @@ private fun KotlinType.approximateNonDynamicFlexibleTypes(preferNotNull: Boolean
|
|||||||
// Foo<Bar!>! -> Foo<Bar>?
|
// Foo<Bar!>! -> Foo<Bar>?
|
||||||
var approximation =
|
var approximation =
|
||||||
if (isCollection)
|
if (isCollection)
|
||||||
TypeUtils.makeNullableAsSpecified(if (isAnnotatedReadOnly()) flexible.upperBound else flexible.lowerBound, !preferNotNull)
|
(if (isAnnotatedReadOnly()) flexible.upperBound else flexible.lowerBound).makeNullableAsSpecified(!preferNotNull)
|
||||||
else
|
else
|
||||||
if (preferNotNull) flexible.lowerBound else flexible.upperBound
|
if (preferNotNull) flexible.lowerBound else flexible.upperBound
|
||||||
|
|
||||||
approximation = approximation.approximateNonDynamicFlexibleTypes()
|
approximation = approximation.approximateNonDynamicFlexibleTypes()
|
||||||
|
|
||||||
approximation = if (isAnnotatedNotNull()) TypeUtils.makeNotNullable(approximation) else approximation
|
approximation = if (isAnnotatedNotNull()) approximation.makeNullableAsSpecified(false) else approximation
|
||||||
|
|
||||||
if (approximation.isMarkedNullable && !flexible.lowerBound.isMarkedNullable && TypeUtils.isTypeParameter(approximation) && TypeUtils.hasNullableSuperType(approximation)) {
|
if (approximation.isMarkedNullable && !flexible.lowerBound.isMarkedNullable && TypeUtils.isTypeParameter(approximation) && TypeUtils.hasNullableSuperType(approximation)) {
|
||||||
approximation = TypeUtils.makeNotNullable(approximation)
|
approximation = approximation.makeNullableAsSpecified(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return approximation
|
return approximation
|
||||||
|
|||||||
Reference in New Issue
Block a user