Use new method instead of some usages of KotlinBuiltIns.getInstance()
This commit is contained in:
+4
-3
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.Variance.IN_VARIANCE
|
||||
import org.jetbrains.kotlin.types.Variance.OUT_VARIANCE
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
|
||||
public class CapturedTypeConstructor(
|
||||
public val typeProjection: TypeProjection
|
||||
@@ -38,7 +39,7 @@ public class CapturedTypeConstructor(
|
||||
val superType = if (typeProjection.getProjectionKind() == Variance.OUT_VARIANCE)
|
||||
typeProjection.getType()
|
||||
else
|
||||
KotlinBuiltIns.getInstance().getNullableAnyType()
|
||||
builtIns.nullableAnyType
|
||||
return listOf(superType)
|
||||
}
|
||||
|
||||
@@ -74,10 +75,10 @@ public class CapturedType(
|
||||
}
|
||||
|
||||
override val subTypeRepresentative: JetType
|
||||
get() = representative(OUT_VARIANCE, KotlinBuiltIns.getInstance().getNullableAnyType())
|
||||
get() = representative(OUT_VARIANCE, builtIns.nullableAnyType)
|
||||
|
||||
override val superTypeRepresentative: JetType
|
||||
get() = representative(IN_VARIANCE, KotlinBuiltIns.getInstance().getNothingType())
|
||||
get() = representative(IN_VARIANCE, builtIns.nothingType)
|
||||
|
||||
private fun representative(variance: Variance, default: JetType) =
|
||||
if (typeProjection.getProjectionKind() == variance) typeProjection.getType() else default
|
||||
|
||||
+2
-1
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.types.TypeUtils.DONT_CARE
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker
|
||||
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure
|
||||
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedureCallbacks
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.typeUtil.getNestedArguments
|
||||
import org.jetbrains.kotlin.types.typeUtil.isDefaultBound
|
||||
import java.util.*
|
||||
@@ -520,7 +521,7 @@ fun createTypeForFunctionPlaceholder(
|
||||
functionPlaceholderTypeConstructor.getArgumentTypes()
|
||||
}
|
||||
val receiverType = if (isExtension) DONT_CARE else null
|
||||
return KotlinBuiltIns.getInstance().getFunctionType(Annotations.EMPTY, receiverType, newArgumentTypes, DONT_CARE)
|
||||
return functionPlaceholder.builtIns.getFunctionType(Annotations.EMPTY, receiverType, newArgumentTypes, DONT_CARE)
|
||||
}
|
||||
|
||||
private fun TypeSubstitutor.setApproximateCapturedTypes(): TypeSubstitutor {
|
||||
|
||||
@@ -23,7 +23,8 @@ import org.jetbrains.kotlin.resolve.calls.inference.isCaptured
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
import java.util.*
|
||||
|
||||
public data class ApproximationBounds<T>(
|
||||
public val lower: T,
|
||||
@@ -39,10 +40,6 @@ private class TypeArgument(
|
||||
get() = JetTypeChecker.DEFAULT.isSubtypeOf(inProjection, outProjection)
|
||||
}
|
||||
|
||||
private val NULLABLE_ANY = KotlinBuiltIns.getInstance().getNullableAnyType()
|
||||
|
||||
private val NOTHING = KotlinBuiltIns.getInstance().getNothingType()
|
||||
|
||||
private fun TypeArgument.toTypeProjection(): TypeProjection {
|
||||
assert(isConsistent) { "Only consistent enhanced type propection can be converted to type projection" }
|
||||
fun removeProjectionIfRedundant(variance: Variance) = if (variance == typeParameter.getVariance()) Variance.INVARIANT else variance
|
||||
@@ -58,8 +55,8 @@ private fun TypeArgument.toTypeProjection(): TypeProjection {
|
||||
private fun TypeProjection.toTypeArgument(typeParameter: TypeParameterDescriptor) =
|
||||
when (TypeSubstitutor.combine(typeParameter.getVariance(), getProjectionKind()) : Variance) {
|
||||
Variance.INVARIANT -> TypeArgument(typeParameter, getType(), getType())
|
||||
Variance.IN_VARIANCE -> TypeArgument(typeParameter, getType(), typeParameter.builtIns.getNullableAnyType())
|
||||
Variance.OUT_VARIANCE -> TypeArgument(typeParameter, typeParameter.builtIns.getNothingType(), getType())
|
||||
Variance.IN_VARIANCE -> TypeArgument(typeParameter, getType(), typeParameter.builtIns.nullableAnyType)
|
||||
Variance.OUT_VARIANCE -> TypeArgument(typeParameter, typeParameter.builtIns.nothingType, type)
|
||||
}
|
||||
|
||||
public fun approximateCapturedTypesIfNecessary(typeProjection: TypeProjection?): TypeProjection? {
|
||||
@@ -97,8 +94,8 @@ public fun approximateCapturedTypes(type: JetType): ApproximationBounds<JetType>
|
||||
val bound = typeProjection.getType().makeNullableIfNeeded()
|
||||
|
||||
return when (typeProjection.getProjectionKind()) {
|
||||
Variance.IN_VARIANCE -> ApproximationBounds(bound, NULLABLE_ANY)
|
||||
Variance.OUT_VARIANCE -> ApproximationBounds(NOTHING.makeNullableIfNeeded(), bound)
|
||||
Variance.IN_VARIANCE -> ApproximationBounds(bound, type.builtIns.nullableAnyType)
|
||||
Variance.OUT_VARIANCE -> ApproximationBounds(type.builtIns.nothingType.makeNullableIfNeeded(), bound)
|
||||
else -> throw AssertionError("Only nontrivial projections should have been captured, not: $typeProjection")
|
||||
}
|
||||
}
|
||||
@@ -114,7 +111,7 @@ public fun approximateCapturedTypes(type: JetType): ApproximationBounds<JetType>
|
||||
}
|
||||
val lowerBoundIsTrivial = lowerBoundArguments.any { !it.isConsistent }
|
||||
return ApproximationBounds(
|
||||
if (lowerBoundIsTrivial) NOTHING else type.replaceTypeArguments(lowerBoundArguments),
|
||||
if (lowerBoundIsTrivial) type.builtIns.nothingType else type.replaceTypeArguments(lowerBoundArguments),
|
||||
type.replaceTypeArguments(upperBoundArguments))
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.kotlin.types.typeUtil.TypeUtilPackage;
|
||||
@@ -67,13 +68,13 @@ public class CommonSupertypes {
|
||||
return max;
|
||||
}
|
||||
|
||||
private static int depth(@NotNull JetType type) {
|
||||
private static int depth(@NotNull final JetType type) {
|
||||
return 1 + maxDepth(KotlinPackage.map(type.getArguments(), new Function1<TypeProjection, JetType>() {
|
||||
@Override
|
||||
public JetType invoke(TypeProjection projection) {
|
||||
if (projection.isStarProjection()) {
|
||||
// any type is good enough for depth here
|
||||
return KotlinBuiltIns.getInstance().getAnyType();
|
||||
return type.getConstructor().getBuiltIns().getAnyType();
|
||||
}
|
||||
return projection.getType();
|
||||
}
|
||||
@@ -136,7 +137,8 @@ public class CommonSupertypes {
|
||||
// Everything deleted => it's Nothing or Nothing?
|
||||
if (typeSet.isEmpty()) {
|
||||
// TODO : attributes
|
||||
return nullable ? KotlinBuiltIns.getInstance().getNullableNothingType() : KotlinBuiltIns.getInstance().getNothingType();
|
||||
KotlinBuiltIns builtIns = types.iterator().next().getConstructor().getBuiltIns();
|
||||
return nullable ? builtIns.getNullableNothingType() : builtIns.getNothingType();
|
||||
}
|
||||
|
||||
if (typeSet.size() == 1) {
|
||||
@@ -256,7 +258,7 @@ public class CommonSupertypes {
|
||||
if (recursionDepth >= maxDepth) {
|
||||
// If recursion is too deep, we cut it by taking <out Any?> as an ultimate supertype argument
|
||||
// Example: class A : Base<A>; class B : Base<B>, commonSuperType(A, B) = Base<out Any?>
|
||||
return new TypeProjectionImpl(OUT_VARIANCE, KotlinBuiltIns.getInstance().getNullableAnyType());
|
||||
return new TypeProjectionImpl(OUT_VARIANCE, DescriptorUtilsKt.getBuiltIns(parameterDescriptor).getNullableAnyType());
|
||||
}
|
||||
|
||||
Set<JetType> ins = new HashSet<JetType>();
|
||||
|
||||
@@ -161,7 +161,7 @@ public class TypeSubstitutor {
|
||||
throw new SubstitutionException("Out-projection in in-position");
|
||||
case IN_IN_OUT_POSITION:
|
||||
// todo use the right type parameter variance and upper bound
|
||||
return new TypeProjectionImpl(Variance.OUT_VARIANCE, KotlinBuiltIns.getInstance().getNullableAnyType());
|
||||
return new TypeProjectionImpl(Variance.OUT_VARIANCE, type.getConstructor().getBuiltIns().getNullableAnyType());
|
||||
}
|
||||
}
|
||||
JetType substitutedType;
|
||||
|
||||
@@ -482,15 +482,20 @@ public class TypeUtils {
|
||||
|
||||
@Nullable
|
||||
private static JetType getDefaultPrimitiveNumberType(@NotNull Collection<JetType> supertypes) {
|
||||
JetType doubleType = KotlinBuiltIns.getInstance().getDoubleType();
|
||||
if (supertypes.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
KotlinBuiltIns builtIns = supertypes.iterator().next().getConstructor().getBuiltIns();
|
||||
JetType doubleType = builtIns.getDoubleType();
|
||||
if (supertypes.contains(doubleType)) {
|
||||
return doubleType;
|
||||
}
|
||||
JetType intType = KotlinBuiltIns.getInstance().getIntType();
|
||||
JetType intType = builtIns.getIntType();
|
||||
if (supertypes.contains(intType)) {
|
||||
return intType;
|
||||
}
|
||||
JetType longType = KotlinBuiltIns.getInstance().getLongType();
|
||||
JetType longType = builtIns.getLongType();
|
||||
if (supertypes.contains(longType)) {
|
||||
return longType;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,9 @@ public fun JetType.nullability(): TypeNullability {
|
||||
}
|
||||
}
|
||||
|
||||
val JetType.builtIns: KotlinBuiltIns
|
||||
get() = constructor.builtIns
|
||||
|
||||
fun JetType.makeNullable() = TypeUtils.makeNullable(this)
|
||||
fun JetType.makeNotNullable() = TypeUtils.makeNotNullable(this)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user