private static <T extends PsiElement> Collection<? extends PsiType> suggestFunctionalInterfaces(final @NotNull T element, final Function<? super PsiClass, ? extends List<? extends PsiType>> acceptanceChecker) {
    final Project project = element.getProject();
    final Set<PsiType> types = new HashSet<>();
    final ReadActionProcessor<PsiMember> consumer = new ReadActionProcessor<>() {
      @Override
      public boolean processInReadAction(PsiMember member) {
        if (member instanceof PsiClass &&
            LanguageLevelUtil.getLastIncompatibleLanguageLevel(member, PsiUtil.getLanguageLevel(element)) == null) {
          if (!JavaPsiFacade.getInstance(project).getResolveHelper().isAccessible(member, element, null)) {
            return true;
          }
          types.addAll(acceptanceChecker.apply((PsiClass)member));
        }
        return true;
      }
    };
    Task.Modal task = new Task.Modal(project, JavaBundle.message("dialog.title.check.functional.interface.candidates"), true) {
      @Override
      public void run(@NotNull ProgressIndicator indicator) {
        final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
        final GlobalSearchScope allScope = GlobalSearchScope.allScope(project);
        final PsiClass functionalInterfaceClass =
          ReadAction.compute(() -> psiFacade.findClass(CommonClassNames.JAVA_LANG_FUNCTIONAL_INTERFACE, allScope));
        if (functionalInterfaceClass != null) {
          AnnotatedMembersSearch.search(functionalInterfaceClass, ReadAction.compute(() -> element.getResolveScope())).forEach(consumer);
        }

        for (String functionalInterface : FUNCTIONAL_INTERFACES) {
          final PsiClass aClass = ReadAction.compute(() -> psiFacade.findClass(functionalInterface, element.getResolveScope()));
          if (aClass != null) {
            consumer.process(aClass);
          }
        }
      }
    };
    if (ApplicationManager.getApplication().isDispatchThread()) {
      ProgressManager.getInstance().run(task);
    }
    else {
      task.run(new EmptyProgressIndicator());
    }

    final ArrayList<PsiType> typesToSuggest = new ArrayList<>(types);
    typesToSuggest.sort(Comparator.comparing(PsiType::getCanonicalText));
    return typesToSuggest;
  }
private static <T extends PsiElement> Collection<? extends PsiType> suggestFunctionalInterfaces(final @NotNull T element, final Function<? super PsiClass, ? extends List<? extends PsiType>> acceptanceChecker)