@Nullable
  static PsiType substituteType(final PsiClassType migrationType, final PsiClassType originalType, boolean captureWildcard, PsiClass originalClass, final PsiType rawTypeToReplace) {
    if (originalClass == null) return null;
    if (!originalType.hasParameters() || !migrationType.hasParameters()) return originalType;
    final PsiResolveHelper psiResolveHelper = JavaPsiFacade.getInstance(originalClass.getProject()).getResolveHelper();
    final PsiType rawOriginalType = JavaPsiFacade.getElementFactory(originalClass.getProject()).createType(originalClass, PsiSubstitutor.EMPTY);

    PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;
    PsiClass migrationClass = migrationType.resolve();
    if (migrationClass == null) return originalType;
    PsiTypeParameter[] parameters = originalClass.getTypeParameters();
    for (PsiTypeParameter parameter : parameters) {
      final PsiType type = psiResolveHelper.getSubstitutionForTypeParameter(parameter, rawOriginalType, migrationType, false,
                                                                            PsiUtil.getLanguageLevel(originalClass));
      if (type != null) {
        substitutor = substitutor.put(parameter, captureWildcard && type instanceof PsiWildcardType wildcardType
                                                 ? wildcardType.getExtendsBound()
                                                 : type);
      }
      else {
        return null;
      }
    }

    return substitutor.substitute(rawTypeToReplace);
  }
@Nullable
  static PsiType substituteType(final PsiClassType migrationType, final PsiClassType originalType, boolean captureWildcard, PsiClass originalClass, final PsiType rawTypeToReplace)