void (final @NotNull List<? extends PsiMember> targets, final @NotNull Consumer<? super List<? extends PsiMember>> selectionConsumer) { if (targets.isEmpty()) { selectionConsumer.consume(Collections.emptyList()); return; } if (targets.size() == 1) { selectionConsumer.consume(Collections.singletonList(targets.get(0))); return; } if (ApplicationManager.getApplication().isUnitTestMode()) { selectionConsumer.consume(targets); return; } targets.sort(new PsiMemberComparator()); final List<Object> model = new ArrayList<>(); String allListed = CodeInsightBundle.message("highlight.thrown.exceptions.chooser.all.entry"); model.add(allListed); model.addAll(targets); final ListCellRenderer<Object> renderer = new NavigationItemListCellRenderer(); JBPopupFactory.getInstance() .createPopupChooserBuilder(model) .setSelectionMode(ListSelectionModel.SINGLE_SELECTION) .setRenderer(renderer) .setNamerForFiltering(o -> { if (o instanceof PsiMember member) { return member.getName(); } return o.toString(); }) .setTitle(myImportStatic ? JavaBundle.message("highlight.imported.members.chooser.title") : JavaBundle.message("highlight.imported.classes.chooser.title")) .setItemChosenCallback((selectedValue) -> { if (selectedValue.equals(allListed)) { selectionConsumer.consume(targets); } else { selectionConsumer.consume(Collections.singletonList((PsiMember)selectedValue)); } }).createPopup().showInBestPositionFor(myEditor); }