use of org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl in project kotlin by JetBrains.
the class SingleAbstractMethodUtils method recreateAndInitializeTypeParameters.
@NotNull
private static TypeParameters recreateAndInitializeTypeParameters(@NotNull List<TypeParameterDescriptor> originalParameters, @Nullable DeclarationDescriptor newOwner) {
if (newOwner instanceof SamAdapterClassConstructorDescriptor) {
return new TypeParameters(originalParameters, TypeSubstitutor.EMPTY);
}
Map<TypeParameterDescriptor, TypeParameterDescriptorImpl> traitToFunTypeParameters = JavaResolverUtils.recreateTypeParametersAndReturnMapping(originalParameters, newOwner);
TypeSubstitutor typeParametersSubstitutor = JavaResolverUtils.createSubstitutorForTypeParameters(traitToFunTypeParameters);
for (Map.Entry<TypeParameterDescriptor, TypeParameterDescriptorImpl> mapEntry : traitToFunTypeParameters.entrySet()) {
TypeParameterDescriptor traitTypeParameter = mapEntry.getKey();
TypeParameterDescriptorImpl funTypeParameter = mapEntry.getValue();
for (KotlinType upperBound : traitTypeParameter.getUpperBounds()) {
KotlinType upperBoundSubstituted = typeParametersSubstitutor.substitute(upperBound, Variance.INVARIANT);
assert upperBoundSubstituted != null : "couldn't substitute type: " + upperBound + ", substitutor = " + typeParametersSubstitutor;
funTypeParameter.addUpperBound(upperBoundSubstituted);
}
funTypeParameter.setInitialized();
}
List<TypeParameterDescriptor> typeParameters = new ArrayList<TypeParameterDescriptor>(traitToFunTypeParameters.values());
return new TypeParameters(typeParameters, typeParametersSubstitutor);
}
use of org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl in project kotlin by JetBrains.
the class DescriptorSubstitutor method substituteTypeParameters.
@NotNull
public static TypeSubstitutor substituteTypeParameters(@ReadOnly @NotNull List<TypeParameterDescriptor> typeParameters, @NotNull TypeSubstitution originalSubstitution, @NotNull DeclarationDescriptor newContainingDeclaration, @NotNull @Mutable List<TypeParameterDescriptor> result) {
Map<TypeConstructor, TypeProjection> mutableSubstitution = new HashMap<TypeConstructor, TypeProjection>();
Map<TypeParameterDescriptor, TypeParameterDescriptorImpl> substitutedMap = new HashMap<TypeParameterDescriptor, TypeParameterDescriptorImpl>();
int index = 0;
for (TypeParameterDescriptor descriptor : typeParameters) {
TypeParameterDescriptorImpl substituted = TypeParameterDescriptorImpl.createForFurtherModification(newContainingDeclaration, descriptor.getAnnotations(), descriptor.isReified(), descriptor.getVariance(), descriptor.getName(), index++, SourceElement.NO_SOURCE);
mutableSubstitution.put(descriptor.getTypeConstructor(), new TypeProjectionImpl(substituted.getDefaultType()));
substitutedMap.put(descriptor, substituted);
result.add(substituted);
}
TypeSubstitutor substitutor = TypeSubstitutor.createChainedSubstitutor(originalSubstitution, TypeConstructorSubstitution.createByConstructorsMap(mutableSubstitution));
for (TypeParameterDescriptor descriptor : typeParameters) {
TypeParameterDescriptorImpl substituted = substitutedMap.get(descriptor);
for (KotlinType upperBound : descriptor.getUpperBounds()) {
KotlinType substitutedBound = substitutor.substitute(upperBound, Variance.IN_VARIANCE);
assert substitutedBound != null : "Upper bound failed to substitute: " + descriptor;
substituted.addUpperBound(substitutedBound);
}
substituted.setInitialized();
}
return substitutor;
}
Aggregations