@NotNull
  public static PsiType getLeastUpperBound(PsiType[] classes, PsiManager manager) {
    PsiElementFactory factory = JavaPsiFacade.getElementFactory(manager.getProject());

    if (classes.length == 0) return factory.createTypeByFQClassName(CommonClassNames.JAVA_LANG_OBJECT);

    PsiType type = classes[0];

    for (int i = 1; i < classes.length; i++) {
      PsiType t = getLeastUpperBound(type, classes[i], manager);
      if (t != null) {
        type = t;
      }
    }

    return type;
  }
@NotNull
  public static PsiType getLeastUpperBound(PsiType[] classes, PsiManager manager)