Minor. Cleanup code

This commit is contained in:
Denis Zharkov
2015-12-18 11:33:29 +03:00
parent 555286849e
commit e7dbcfe21f
3 changed files with 17 additions and 17 deletions
@@ -45,10 +45,10 @@ public class SubstitutingScope(private val workerScope: MemberScope, private val
}
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
val result = newHashSetWithExpectedSize<D>(descriptors.size())
val result = newHashSetWithExpectedSize<D>(descriptors.size)
for (descriptor in descriptors) {
val substitute = substitute(descriptor)
if (substitute != null) {
@@ -53,9 +53,9 @@ private fun TypeArgument.toTypeProjection(): TypeProjection {
}
private fun TypeProjection.toTypeArgument(typeParameter: TypeParameterDescriptor) =
when (TypeSubstitutor.combine(typeParameter.getVariance(), getProjectionKind())) {
Variance.INVARIANT -> TypeArgument(typeParameter, getType(), getType())
Variance.IN_VARIANCE -> TypeArgument(typeParameter, getType(), typeParameter.builtIns.nullableAnyType)
when (TypeSubstitutor.combine(typeParameter.variance, projectionKind)) {
Variance.INVARIANT -> TypeArgument(typeParameter, type, type)
Variance.IN_VARIANCE -> TypeArgument(typeParameter, type, typeParameter.builtIns.nullableAnyType)
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> {
val typeConstructor = type.getConstructor()
val typeConstructor = type.constructor
if (type.isCaptured()) {
val typeProjection = (typeConstructor as CapturedTypeConstructor).typeProjection
// todo: preserve flexibility as well
fun KotlinType.makeNullableIfNeeded() = TypeUtils.makeNullableIfNeeded(this, type.isMarkedNullable())
val bound = typeProjection.getType().makeNullableIfNeeded()
fun KotlinType.makeNullableIfNeeded() = TypeUtils.makeNullableIfNeeded(this, type.isMarkedNullable)
val bound = typeProjection.type.makeNullableIfNeeded()
return when (typeProjection.getProjectionKind()) {
return when (typeProjection.projectionKind) {
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")
}
}
if (type.getArguments().isEmpty()) {
if (type.arguments.isEmpty()) {
return ApproximationBounds(type, type)
}
val lowerBoundArguments = 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))
lowerBoundArguments.add(lower)
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() {
@@ -131,7 +131,7 @@ private class CompositeTypeSubstitution(
}
override fun isEmpty() = first.isEmpty() && second.isEmpty()
//
override fun approximateCapturedTypes() = first.approximateCapturedTypes() || second.approximateCapturedTypes()
override fun filterAnnotations(annotations: Annotations): Annotations = second.filterAnnotations(first.filterAnnotations(annotations))