private static @Nullable PsiType trySubstitute(@NotNull PsiType type, @NotNull PsiClass superClass) {
    if (!(type instanceof PsiClassType)) return null;
    PsiClassType.ClassResolveResult result = ((PsiClassType)type).resolveGenerics();
    PsiClass psiClass = result.getElement();
    if (psiClass == null) return null;
    if (!psiClass.isInheritor(superClass, true)) return null;
    PsiSubstitutor substitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, psiClass, result.getSubstitutor());
    return JavaPsiFacade.getElementFactory(superClass.getProject()).createType(superClass, substitutor);
  }
private static @Nullable PsiType trySubstitute(@NotNull PsiType type, @NotNull PsiClass superClass)