void () { PsiDocumentManager.getInstance(myProject).commitAllDocuments(); Ref<@Nls String> problemDetected = new Ref<>(); final PsiElement[][] result = new PsiElement[1][]; ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> ApplicationManager.getApplication().runReadAction(() -> { final PsiClass psiClass = myMethod.getContainingClass(); if (!psiClass.isValid()) return; if (!psiClass.isEnum()) { result[0] = getClassImplementations(psiClass, problemDetected); } else { final List<PsiElement> enumConstants = new ArrayList<>(); for (PsiField field : psiClass.getFields()) { if (field instanceof PsiEnumConstant) { final PsiEnumConstantInitializer initializingClass = ((PsiEnumConstant)field).getInitializingClass(); if (initializingClass != null) { PsiMethod method = initializingClass.findMethodBySignature(myMethod, true); if (method == null || !method.getContainingClass().equals(initializingClass)) { enumConstants.add(initializingClass); } } else { enumConstants.add(field); } } } result[0] = PsiUtilCore.toPsiElementArray(enumConstants); } }), JavaBundle.message("intention.implement.abstract.method.searching.for.descendants.progress"), true, myProject); PsiElement[] elements = result[0]; if (elements == null) return; if (elements.length == 0) { Messages.showMessageDialog(myProject, problemDetected.isNull() ? JavaBundle.message("intention.implement.abstract.method.error.no.classes.message") : problemDetected.get(), JavaBundle.message("intention.implement.abstract.method.error.no.classes.title"), Messages.getInformationIcon()); return; } if (elements.length == 1) { implementInClass(new Object[]{elements[0]}); return; } final MyPsiElementListCellRenderer elementListCellRenderer = new MyPsiElementListCellRenderer(); elementListCellRenderer.sort(elements); final IPopupChooserBuilder<PsiElement> builder = JBPopupFactory.getInstance() .createPopupChooserBuilder(List.of(elements)) .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) .setRenderer(elementListCellRenderer) .setTitle(CodeInsightBundle.message("intention.implement.abstract.method.class.chooser.title")). setItemsChosenCallback((selectedValues) -> { if (!selectedValues.isEmpty()) { implementInClass(ArrayUtil.toObjectArray(selectedValues)); } }) .withHintUpdateSupply(); elementListCellRenderer.installSpeedSearch(builder); builder.createPopup().showInBestPositionFor(myEditor); }