Minor. Cleanup code
This commit is contained in:
@@ -45,10 +45,10 @@ public class SubstitutingScope(private val workerScope: MemberScope, private val
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun <D : DeclarationDescriptor> substitute(descriptors: Collection<D>): Collection<D> {
|
private fun <D : DeclarationDescriptor> substitute(descriptors: Collection<D>): Collection<D> {
|
||||||
if (substitutor.isEmpty()) return descriptors
|
if (substitutor.isEmpty) return descriptors
|
||||||
if (descriptors.isEmpty()) return descriptors
|
if (descriptors.isEmpty()) return descriptors
|
||||||
|
|
||||||
val result = newHashSetWithExpectedSize<D>(descriptors.size())
|
val result = newHashSetWithExpectedSize<D>(descriptors.size)
|
||||||
for (descriptor in descriptors) {
|
for (descriptor in descriptors) {
|
||||||
val substitute = substitute(descriptor)
|
val substitute = substitute(descriptor)
|
||||||
if (substitute != null) {
|
if (substitute != null) {
|
||||||
|
|||||||
@@ -53,9 +53,9 @@ private fun TypeArgument.toTypeProjection(): TypeProjection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun TypeProjection.toTypeArgument(typeParameter: TypeParameterDescriptor) =
|
private fun TypeProjection.toTypeArgument(typeParameter: TypeParameterDescriptor) =
|
||||||
when (TypeSubstitutor.combine(typeParameter.getVariance(), getProjectionKind())) {
|
when (TypeSubstitutor.combine(typeParameter.variance, projectionKind)) {
|
||||||
Variance.INVARIANT -> TypeArgument(typeParameter, getType(), getType())
|
Variance.INVARIANT -> TypeArgument(typeParameter, type, type)
|
||||||
Variance.IN_VARIANCE -> TypeArgument(typeParameter, getType(), typeParameter.builtIns.nullableAnyType)
|
Variance.IN_VARIANCE -> TypeArgument(typeParameter, type, typeParameter.builtIns.nullableAnyType)
|
||||||
Variance.OUT_VARIANCE -> TypeArgument(typeParameter, typeParameter.builtIns.nothingType, type)
|
Variance.OUT_VARIANCE -> TypeArgument(typeParameter, typeParameter.builtIns.nothingType, type)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,25 +86,25 @@ private fun substituteCapturedTypes(typeProjection: TypeProjection): TypeProject
|
|||||||
}
|
}
|
||||||
|
|
||||||
public fun approximateCapturedTypes(type: KotlinType): ApproximationBounds<KotlinType> {
|
public fun approximateCapturedTypes(type: KotlinType): ApproximationBounds<KotlinType> {
|
||||||
val typeConstructor = type.getConstructor()
|
val typeConstructor = type.constructor
|
||||||
if (type.isCaptured()) {
|
if (type.isCaptured()) {
|
||||||
val typeProjection = (typeConstructor as CapturedTypeConstructor).typeProjection
|
val typeProjection = (typeConstructor as CapturedTypeConstructor).typeProjection
|
||||||
// todo: preserve flexibility as well
|
// todo: preserve flexibility as well
|
||||||
fun KotlinType.makeNullableIfNeeded() = TypeUtils.makeNullableIfNeeded(this, type.isMarkedNullable())
|
fun KotlinType.makeNullableIfNeeded() = TypeUtils.makeNullableIfNeeded(this, type.isMarkedNullable)
|
||||||
val bound = typeProjection.getType().makeNullableIfNeeded()
|
val bound = typeProjection.type.makeNullableIfNeeded()
|
||||||
|
|
||||||
return when (typeProjection.getProjectionKind()) {
|
return when (typeProjection.projectionKind) {
|
||||||
Variance.IN_VARIANCE -> ApproximationBounds(bound, type.builtIns.nullableAnyType)
|
Variance.IN_VARIANCE -> ApproximationBounds(bound, type.builtIns.nullableAnyType)
|
||||||
Variance.OUT_VARIANCE -> ApproximationBounds(type.builtIns.nothingType.makeNullableIfNeeded(), bound)
|
Variance.OUT_VARIANCE -> ApproximationBounds(type.builtIns.nothingType.makeNullableIfNeeded(), bound)
|
||||||
else -> throw AssertionError("Only nontrivial projections should have been captured, not: $typeProjection")
|
else -> throw AssertionError("Only nontrivial projections should have been captured, not: $typeProjection")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (type.getArguments().isEmpty()) {
|
if (type.arguments.isEmpty()) {
|
||||||
return ApproximationBounds(type, type)
|
return ApproximationBounds(type, type)
|
||||||
}
|
}
|
||||||
val lowerBoundArguments = ArrayList<TypeArgument>()
|
val lowerBoundArguments = ArrayList<TypeArgument>()
|
||||||
val upperBoundArguments = ArrayList<TypeArgument>()
|
val upperBoundArguments = ArrayList<TypeArgument>()
|
||||||
for ((typeProjection, typeParameter) in type.getArguments().zip(typeConstructor.getParameters())) {
|
for ((typeProjection, typeParameter) in type.arguments.zip(typeConstructor.parameters)) {
|
||||||
val (lower, upper) = approximateProjection(typeProjection.toTypeArgument(typeParameter))
|
val (lower, upper) = approximateProjection(typeProjection.toTypeArgument(typeParameter))
|
||||||
lowerBoundArguments.add(lower)
|
lowerBoundArguments.add(lower)
|
||||||
upperBoundArguments.add(upper)
|
upperBoundArguments.add(upper)
|
||||||
|
|||||||
@@ -29,15 +29,15 @@ public abstract class TypeSubstitution {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract operator fun get(key: KotlinType): TypeProjection?
|
abstract operator fun get(key: KotlinType): TypeProjection?
|
||||||
|
|
||||||
public open fun isEmpty(): Boolean = false
|
open fun isEmpty(): Boolean = false
|
||||||
|
|
||||||
public open fun approximateCapturedTypes(): Boolean = false
|
open fun approximateCapturedTypes(): Boolean = false
|
||||||
|
|
||||||
public open fun filterAnnotations(annotations: Annotations) = annotations
|
open fun filterAnnotations(annotations: Annotations) = annotations
|
||||||
|
|
||||||
public fun buildSubstitutor(): TypeSubstitutor = TypeSubstitutor.create(this)
|
fun buildSubstitutor(): TypeSubstitutor = TypeSubstitutor.create(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class TypeConstructorSubstitution : TypeSubstitution() {
|
public abstract class TypeConstructorSubstitution : TypeSubstitution() {
|
||||||
@@ -131,7 +131,7 @@ private class CompositeTypeSubstitution(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun isEmpty() = first.isEmpty() && second.isEmpty()
|
override fun isEmpty() = first.isEmpty() && second.isEmpty()
|
||||||
//
|
|
||||||
override fun approximateCapturedTypes() = first.approximateCapturedTypes() || second.approximateCapturedTypes()
|
override fun approximateCapturedTypes() = first.approximateCapturedTypes() || second.approximateCapturedTypes()
|
||||||
|
|
||||||
override fun filterAnnotations(annotations: Annotations): Annotations = second.filterAnnotations(first.filterAnnotations(annotations))
|
override fun filterAnnotations(annotations: Annotations): Annotations = second.filterAnnotations(first.filterAnnotations(annotations))
|
||||||
|
|||||||
Reference in New Issue
Block a user