@NotNull
  private <R extends PsiElement> PsiQuery<R> getQueryWithProducer(@NotNull final Function<? super T, ? extends Collection<R>> elementsProducer,
                                                                  @NotNull final PsiFilter<R> filter) {
    final Set<R> result = new LinkedHashSet<>(); // Set to get rid of duplicates but preserve order
    asStream()
      .map(o -> ContainerUtil.filter(elementsProducer.apply(o), o2 -> !o2.equals(o)))
      .forEach(result::addAll);
    return new PsiQuery<>(new ArrayList<>(filter.filter(result)));
  }
@NotNull
  private <R extends PsiElement> PsiQuery<R> getQueryWithProducer(@NotNull final Function<? super T, ? extends Collection<R>> elementsProducer,
                                                                  @NotNull final PsiFilter<R> filter)