public static List<PsiType> flattenAndRemoveDuplicates(@NotNull List<? extends PsiType> types) {
    Set<PsiType> disjunctionSet = new LinkedHashSet<>();
    for (PsiType type : types) {
      flatten(disjunctionSet, type);
    }
    ArrayList<PsiType> disjunctions = new ArrayList<>(disjunctionSet);
    for (Iterator<PsiType> iterator = disjunctions.iterator(); iterator.hasNext(); ) {
      PsiType d1 = iterator.next();
      for (PsiType d2 : disjunctions) {
        if (d1 != d2 && d2.isAssignableFrom(d1)) {
          iterator.remove();
          break;
        }
      }
    }
    return disjunctions;
  }
public static List<PsiType> flattenAndRemoveDuplicates(@NotNull List<? extends PsiType> types)