void () { if (myClasses.length == 1) { selected((T[])ArrayUtil.toObjectArray(myClasses[0].getClass(), myClasses[0])); } else if (myClasses.length > 0) { PsiElementListCellRenderer<T> renderer = createRenderer(); Arrays.sort(myClasses, renderer.getComparator()); if (ApplicationManager.getApplication().isUnitTestMode()) { selected(myClasses); return; } List<Object> model = new ArrayList<>(Arrays.asList(myClasses)); String selectAll = CodeInsightBundle.message("highlight.thrown.exceptions.chooser.all.entry"); model.add(0, selectAll); IPopupChooserBuilder<Object> builder = JBPopupFactory.getInstance() .createPopupChooserBuilder(model) .setRenderer(renderer) // exploit PsiElementListCellRenderer ability to render strings too .setSelectionMode(ListSelectionModel.SINGLE_SELECTION) .setItemChosenCallback(selectedValue -> { if (selectedValue.equals(selectAll)) { selected(myClasses); } else { selected((T[])ArrayUtil.toObjectArray(selectedValue.getClass(), selectedValue)); } }) .setTitle(myTitle); renderer.installSpeedSearch(builder); ApplicationManager.getApplication().invokeLater(() -> builder .createPopup() .showInBestPositionFor(myEditor)); } }