@NotNull
 public static TypeSubstitutor createSubstitutorForTypeParameters(
     @NotNull
         Map<TypeParameterDescriptor, TypeParameterDescriptorImpl> originalToAltTypeParameters) {
   Map<TypeConstructor, TypeProjection> typeSubstitutionContext =
       new HashMap<TypeConstructor, TypeProjection>();
   for (Map.Entry<TypeParameterDescriptor, TypeParameterDescriptorImpl>
       originalToAltTypeParameter : originalToAltTypeParameters.entrySet()) {
     typeSubstitutionContext.put(
         originalToAltTypeParameter.getKey().getTypeConstructor(),
         new TypeProjectionImpl(originalToAltTypeParameter.getValue().getDefaultType()));
   }
   return TypeSubstitutor.create(typeSubstitutionContext);
 }
 @NotNull
 public static Map<TypeParameterDescriptor, TypeParameterDescriptorImpl>
     recreateTypeParametersAndReturnMapping(
         @NotNull List<TypeParameterDescriptor> originalParameters,
         @Nullable DeclarationDescriptor newOwner) {
   // LinkedHashMap to save the order of type parameters
   Map<TypeParameterDescriptor, TypeParameterDescriptorImpl> result =
       new LinkedHashMap<TypeParameterDescriptor, TypeParameterDescriptorImpl>();
   for (TypeParameterDescriptor typeParameter : originalParameters) {
     result.put(
         typeParameter,
         TypeParameterDescriptorImpl.createForFurtherModification(
             newOwner == null ? typeParameter.getContainingDeclaration() : newOwner,
             typeParameter.getAnnotations(),
             typeParameter.isReified(),
             typeParameter.getVariance(),
             typeParameter.getName(),
             typeParameter.getIndex()));
   }
   return result;
 }