use of org.jetbrains.kotlin.types.TypeProjection in project kotlin by JetBrains.
the class ResolvedCallImpl method setResultingSubstitutor.
@Override
public void setResultingSubstitutor(@NotNull TypeSubstitutor substitutor) {
resultingDescriptor = (D) candidateDescriptor.substitute(substitutor);
assert resultingDescriptor != null : candidateDescriptor;
for (TypeParameterDescriptor typeParameter : candidateDescriptor.getTypeParameters()) {
TypeProjection typeArgumentProjection = substitutor.getSubstitution().get(typeParameter.getDefaultType());
if (typeArgumentProjection != null) {
typeArguments.put(typeParameter, typeArgumentProjection.getType());
}
}
if (candidateDescriptor.getValueParameters().isEmpty())
return;
List<ValueParameterDescriptor> substitutedParameters = resultingDescriptor.getValueParameters();
Collection<Map.Entry<ValueParameterDescriptor, ResolvedValueArgument>> valueArgumentsBeforeSubstitution = new SmartList<Map.Entry<ValueParameterDescriptor, ResolvedValueArgument>>(valueArguments.entrySet());
valueArguments.clear();
for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> entry : valueArgumentsBeforeSubstitution) {
ValueParameterDescriptor substitutedVersion = substitutedParameters.get(entry.getKey().getIndex());
assert substitutedVersion != null : entry.getKey();
valueArguments.put(substitutedVersion, entry.getValue());
}
Collection<Map.Entry<ValueArgument, ArgumentMatchImpl>> unsubstitutedArgumentMappings = new SmartList<Map.Entry<ValueArgument, ArgumentMatchImpl>>(argumentToParameterMap.entrySet());
argumentToParameterMap.clear();
for (Map.Entry<ValueArgument, ArgumentMatchImpl> entry : unsubstitutedArgumentMappings) {
ArgumentMatchImpl argumentMatch = entry.getValue();
ValueParameterDescriptor valueParameterDescriptor = argumentMatch.getValueParameter();
ValueParameterDescriptor substitutedVersion = substitutedParameters.get(valueParameterDescriptor.getIndex());
assert substitutedVersion != null : valueParameterDescriptor;
argumentToParameterMap.put(entry.getKey(), argumentMatch.replaceValueParameter(substitutedVersion));
}
}
use of org.jetbrains.kotlin.types.TypeProjection in project kotlin by JetBrains.
the class ForceResolveUtil method forceResolveAllContents.
@Nullable
public static KotlinType forceResolveAllContents(@Nullable KotlinType type) {
if (type == null)
return null;
forceResolveAllContents(type.getAnnotations());
if (FlexibleTypesKt.isFlexible(type)) {
forceResolveAllContents(FlexibleTypesKt.asFlexibleType(type).getLowerBound());
forceResolveAllContents(FlexibleTypesKt.asFlexibleType(type).getUpperBound());
} else {
forceResolveAllContents(type.getConstructor());
for (TypeProjection projection : type.getArguments()) {
if (!projection.isStarProjection()) {
forceResolveAllContents(projection.getType());
}
}
}
return type;
}
use of org.jetbrains.kotlin.types.TypeProjection in project kotlin by JetBrains.
the class CompileTimeConstantUtils method isAcceptableTypeForAnnotationParameter.
private static boolean isAcceptableTypeForAnnotationParameter(@NotNull KotlinType parameterType) {
ClassDescriptor typeDescriptor = TypeUtils.getClassDescriptor(parameterType);
if (typeDescriptor == null) {
return false;
}
if (isEnumClass(typeDescriptor) || isAnnotationClass(typeDescriptor) || KotlinBuiltIns.isKClass(typeDescriptor) || KotlinBuiltIns.isPrimitiveArray(parameterType) || KotlinBuiltIns.isPrimitiveType(parameterType) || KotlinBuiltIns.isString(parameterType)) {
return true;
}
if (KotlinBuiltIns.isArray(parameterType)) {
List<TypeProjection> arguments = parameterType.getArguments();
if (arguments.size() == 1) {
KotlinType arrayType = arguments.get(0).getType();
if (arrayType.isMarkedNullable()) {
return false;
}
ClassDescriptor arrayTypeDescriptor = TypeUtils.getClassDescriptor(arrayType);
if (arrayTypeDescriptor != null) {
return isEnumClass(arrayTypeDescriptor) || isAnnotationClass(arrayTypeDescriptor) || KotlinBuiltIns.isKClass(arrayTypeDescriptor) || KotlinBuiltIns.isString(arrayType);
}
}
}
return false;
}
use of org.jetbrains.kotlin.types.TypeProjection in project kotlin by JetBrains.
the class AbstractAnnotationDescriptorResolveTest method getPropertyDescriptor.
@Nullable
protected static PropertyDescriptor getPropertyDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name, boolean failOnMissing) {
Name propertyName = Name.identifier(name);
MemberScope memberScope = packageView.getMemberScope();
Collection<PropertyDescriptor> properties = memberScope.getContributedVariables(propertyName, NoLookupLocation.FROM_TEST);
if (properties.isEmpty()) {
for (DeclarationDescriptor descriptor : DescriptorUtils.getAllDescriptors(memberScope)) {
if (descriptor instanceof ClassDescriptor) {
Collection<PropertyDescriptor> classProperties = ((ClassDescriptor) descriptor).getMemberScope(Collections.<TypeProjection>emptyList()).getContributedVariables(propertyName, NoLookupLocation.FROM_TEST);
if (!classProperties.isEmpty()) {
properties = classProperties;
break;
}
}
}
}
if (failOnMissing) {
assert properties.size() == 1 : "Failed to find property " + propertyName + " in class " + packageView.getName();
} else if (properties.size() != 1) {
return null;
}
return properties.iterator().next();
}
use of org.jetbrains.kotlin.types.TypeProjection 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;
}
Aggregations