Search in sources :

Example 1 with TypeAliasConstructorDescriptor

use of org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor in project kotlin by JetBrains.

the class ExpressionCodegen method getTypeArgumentsForResolvedCall.

@NotNull
private static Map<TypeParameterDescriptor, KotlinType> getTypeArgumentsForResolvedCall(@NotNull ResolvedCall<?> resolvedCall, @NotNull CallableDescriptor descriptor) {
    if (!(descriptor instanceof TypeAliasConstructorDescriptor)) {
        return resolvedCall.getTypeArguments();
    }
    TypeAliasConstructorDescriptor typeAliasConstructorDescriptor = (TypeAliasConstructorDescriptor) descriptor;
    ClassConstructorDescriptor underlyingConstructorDescriptor = typeAliasConstructorDescriptor.getUnderlyingConstructorDescriptor();
    KotlinType resultingType = typeAliasConstructorDescriptor.getReturnType();
    List<TypeProjection> typeArgumentsForReturnType = resultingType.getArguments();
    List<TypeParameterDescriptor> typeParameters = underlyingConstructorDescriptor.getTypeParameters();
    assert typeParameters.size() == typeArgumentsForReturnType.size() : "Type parameters of the underlying constructor " + underlyingConstructorDescriptor + "should correspond to type arguments for the resulting type " + resultingType;
    Map<TypeParameterDescriptor, KotlinType> typeArgumentsMap = Maps.newHashMapWithExpectedSize(typeParameters.size());
    for (TypeParameterDescriptor typeParameter : typeParameters) {
        KotlinType typeArgument = typeArgumentsForReturnType.get(typeParameter.getIndex()).getType();
        typeArgumentsMap.put(typeParameter, typeArgument);
    }
    return typeArgumentsMap;
}
Also used : TypeProjection(org.jetbrains.kotlin.types.TypeProjection) KotlinType(org.jetbrains.kotlin.types.KotlinType) TypeAliasConstructorDescriptor(org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)1 TypeAliasConstructorDescriptor (org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1 TypeProjection (org.jetbrains.kotlin.types.TypeProjection)1