From a6da15f8e2cacc9ae685e5423d5eed372b035a28 Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Thu, 2 Jun 2016 07:30:14 +0300 Subject: [PATCH] Minor. remove several methods from TypeUtils --- .../kotlin/backend/common/CodegenUtil.kt | 4 ++-- .../codegen/inline/ReifiedTypeInliner.kt | 4 ++-- .../java/sam/SingleAbstractMethodUtils.java | 2 +- ...nExpansiveInheritanceRestrictionChecker.kt | 4 ++-- .../java/lazy/types/LazyJavaTypeResolver.kt | 9 ++++----- .../java/typeEnhancement/typeEnhancement.kt | 2 +- .../kotlin/builtins/KotlinBuiltIns.java | 4 ++-- .../org/jetbrains/kotlin/types/TypeUtils.java | 20 ++++--------------- .../org/jetbrains/kotlin/types/TypeUtils.kt | 1 - .../jetbrains/kotlin/types/flexibleTypes.kt | 3 +-- .../jetbrains/kotlin/idea/util/TypeUtils.kt | 6 +++--- 11 files changed, 22 insertions(+), 37 deletions(-) diff --git a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.kt b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.kt index 4737a3d8875..8c84bd698fe 100644 --- a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.kt +++ b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.kt @@ -27,9 +27,9 @@ import org.jetbrains.kotlin.resolve.MemberComparator import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.checker.KotlinTypeChecker import org.jetbrains.kotlin.types.isDynamic +import org.jetbrains.kotlin.types.typeUtil.makeNullable import org.jetbrains.kotlin.utils.keysToMapExceptNulls object CodegenUtil { @@ -156,7 +156,7 @@ object CodegenUtil { @JvmStatic fun isEnumValueOfMethod(functionDescriptor: FunctionDescriptor): Boolean { val methodTypeParameters = functionDescriptor.valueParameters - val nullableString = TypeUtils.makeNullable(functionDescriptor.builtIns.stringType) + val nullableString = functionDescriptor.builtIns.stringType.makeNullable() return DescriptorUtils.ENUM_VALUE_OF == functionDescriptor.name && methodTypeParameters.size == 1 && KotlinTypeChecker.DEFAULT.isSubtypeOf(methodTypeParameters[0].type, nullableString) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ReifiedTypeInliner.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ReifiedTypeInliner.kt index 82092757b6b..7245cb07755 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ReifiedTypeInliner.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ReifiedTypeInliner.kt @@ -22,9 +22,9 @@ import org.jetbrains.kotlin.codegen.generateIsCheck import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods import org.jetbrains.kotlin.codegen.optimization.common.intConstant import org.jetbrains.kotlin.types.KotlinType +import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.Variance 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.Opcodes import org.jetbrains.org.objectweb.asm.Type @@ -43,7 +43,7 @@ class ReificationArgument( ) 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 { val builtins = this.builtIns diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SingleAbstractMethodUtils.java b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SingleAbstractMethodUtils.java index 33e160041b7..b422f71e4ea 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SingleAbstractMethodUtils.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SingleAbstractMethodUtils.java @@ -73,7 +73,7 @@ public class SingleAbstractMethodUtils { if (FlexibleTypesKt.isNullabilityFlexible(samType)) { 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()); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/NonExpansiveInheritanceRestrictionChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/NonExpansiveInheritanceRestrictionChecker.kt index ec1d4435e38..c0aaf6f0bd4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/NonExpansiveInheritanceRestrictionChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/NonExpansiveInheritanceRestrictionChecker.kt @@ -103,7 +103,7 @@ object NonExpansiveInheritanceRestrictionChecker { val constituents = constituentTypes(setOf(typeProjection.type)) 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)) } } @@ -126,7 +126,7 @@ object NonExpansiveInheritanceRestrictionChecker { val boundClosure = boundClosure(bounds) val constituentTypes = constituentTypes(boundClosure) 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) } } diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt index 79e25d316d9..392dbf49e06 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt @@ -35,7 +35,6 @@ import org.jetbrains.kotlin.platform.JavaToKotlinClassMap import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.Variance.* 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.utils.sure import org.jetbrains.kotlin.utils.toReadOnlyList @@ -90,8 +89,8 @@ class LazyJavaTypeResolver( if (primitiveType != null) { val jetType = c.module.builtIns.getPrimitiveArrayKotlinType(primitiveType) return@run if (attr.allowFlexible) - KotlinTypeFactory.flexibleType(jetType, TypeUtils.makeNullable(jetType)) - else TypeUtils.makeNullableAsSpecified(jetType, !attr.isMarkedNotNull) + KotlinTypeFactory.flexibleType(jetType, jetType.makeNullableAsSpecified(true)) + else jetType.makeNullableAsSpecified(!attr.isMarkedNotNull) } val componentType = transformJavaType(javaComponentType, @@ -100,12 +99,12 @@ class LazyJavaTypeResolver( if (attr.allowFlexible) { return@run KotlinTypeFactory.flexibleType( 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 result = c.module.builtIns.getArrayType(projectionKind, componentType) - return@run TypeUtils.makeNullableAsSpecified(result, !attr.isMarkedNotNull) + return@run result.makeNullableAsSpecified(!attr.isMarkedNotNull) }.replaceAnnotations(attr.typeAnnotations) } diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeEnhancement.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeEnhancement.kt index b8ea0daacea..084c86be319 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeEnhancement.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeEnhancement.kt @@ -235,7 +235,7 @@ internal class NotNullTypeParameter(override val delegate: SimpleType) : CustomT get() = false private fun SimpleType.prepareReplacement(): SimpleType { - val result = TypeUtils.makeNullableAsSpecified(this, false) + val result = makeNullableAsSpecified(false) if (!this.isTypeParameter()) return result return NotNullTypeParameter(result) diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java index b95c64fecc7..2d1bdbf5668 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java @@ -612,7 +612,7 @@ public abstract class KotlinBuiltIns { @NotNull public SimpleType getNullableNothingType() { - return TypeUtils.makeNullable(getNothingType()); + return getNothingType().makeNullableAsSpecified(true); } @NotNull @@ -622,7 +622,7 @@ public abstract class KotlinBuiltIns { @NotNull public SimpleType getNullableAnyType() { - return TypeUtils.makeNullable(getAnyType()); + return getAnyType().makeNullableAsSpecified(true); } @NotNull diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java index 7aa3b21f4d0..700717876f8 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java @@ -95,21 +95,6 @@ public class TypeUtils { 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 public static KotlinType makeNullableAsSpecified(@NotNull KotlinType type, boolean nullable) { return type.unwrap().makeNullableAsSpecified(nullable); @@ -117,7 +102,10 @@ public class TypeUtils { @NotNull 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 diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt index 1ba06b8c3d1..7aeabc89153 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt @@ -45,7 +45,6 @@ val KotlinType.builtIns: KotlinBuiltIns get() = constructor.builtIns fun KotlinType.makeNullable() = TypeUtils.makeNullable(this) -fun KotlinType.makeNullableIfNeeded(nullable: Boolean) = TypeUtils.makeNullableIfNeeded(this, nullable) fun KotlinType.makeNotNullable() = TypeUtils.makeNotNullable(this) fun KotlinType.immediateSupertypes(): Collection = TypeUtils.getImmediateSupertypes(this) diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt index 66a1157bc1f..716d3042513 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt @@ -21,7 +21,6 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.renderer.DescriptorRendererOptions import org.jetbrains.kotlin.types.checker.KotlinTypeChecker -import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations fun KotlinType.isFlexible(): Boolean = unwrap() is FlexibleType @@ -117,7 +116,7 @@ class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : Flexibl val unwrapped = replacement.unwrap() return when(unwrapped) { is FlexibleType -> unwrapped - is SimpleType -> KotlinTypeFactory.flexibleType(unwrapped, TypeUtils.makeNullable(unwrapped)) + is SimpleType -> KotlinTypeFactory.flexibleType(unwrapped, unwrapped.makeNullableAsSpecified(true)) } } diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/TypeUtils.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/TypeUtils.kt index e44ef08a734..31086bc2529 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/TypeUtils.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/TypeUtils.kt @@ -48,16 +48,16 @@ private fun KotlinType.approximateNonDynamicFlexibleTypes(preferNotNull: Boolean // Foo! -> Foo? var approximation = if (isCollection) - TypeUtils.makeNullableAsSpecified(if (isAnnotatedReadOnly()) flexible.upperBound else flexible.lowerBound, !preferNotNull) + (if (isAnnotatedReadOnly()) flexible.upperBound else flexible.lowerBound).makeNullableAsSpecified(!preferNotNull) else if (preferNotNull) flexible.lowerBound else flexible.upperBound 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)) { - approximation = TypeUtils.makeNotNullable(approximation) + approximation = approximation.makeNullableAsSpecified(false) } return approximation