public static PsiType substituteType(final PsiType migrationType, final PsiType originalType, final boolean isContraVariantPosition) {
    if (originalType instanceof PsiClassType originalClassType && migrationType instanceof PsiClassType migrationClassType) {
      final PsiClass originalClass = originalClassType.resolve();
      if (originalClass != null) {
        if (isContraVariantPosition && TypeConversionUtil.erasure(originalType).isAssignableFrom(TypeConversionUtil.erasure(migrationType))) {
          PsiClassType.ClassResolveResult resolveResult = migrationClassType.resolveGenerics();
          final PsiClass psiClass = resolveResult.getElement();
          final PsiSubstitutor substitutor = 
            psiClass != null ? TypeConversionUtil.getClassSubstitutor(originalClass, psiClass, resolveResult.getSubstitutor()) : null;
          if (substitutor != null) {
            final PsiType psiType =
                substituteType(migrationClassType, originalClassType, false, psiClass, JavaPsiFacade.getElementFactory(psiClass.getProject()).createType(originalClass, substitutor));
            if (psiType != null) {
              return psiType;
            }
          }
        }
        else if (!isContraVariantPosition && TypeConversionUtil.erasure(migrationType).isAssignableFrom(TypeConversionUtil.erasure(originalType))) {
          final PsiType psiType = substituteType(migrationClassType, originalClassType, false, originalClass, 
                                                 JavaPsiFacade.getElementFactory(originalClass.getProject()).createType(originalClass, PsiSubstitutor.EMPTY));
          if (psiType != null) {
            return psiType;
          }
        }
      }
    }
    return migrationType;
  }
public static PsiType substituteType(final PsiType migrationType, final PsiType originalType, final boolean isContraVariantPosition)