Minor. remove several methods from TypeUtils

This commit is contained in:
Stanislav Erokhin
2016-06-02 07:30:14 +03:00
parent f41c8dc045
commit a6da15f8e2
11 changed files with 22 additions and 37 deletions
@@ -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)
}
@@ -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)
@@ -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
@@ -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
@@ -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<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.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))
}
}