Promise<ImportCandidateHolder> (List<? extends ImportCandidateHolder> sources, boolean useQualifiedImport) { if (ApplicationManager.getApplication().isUnitTestMode()) { return Promises.resolvedPromise(sources.get(0)); } AsyncPromise<ImportCandidateHolder> result = new AsyncPromise<>(); // GUI part DataManager.getInstance().getDataContextFromFocus().doWhenDone((Consumer<DataContext>)dataContext -> JBPopupFactory.getInstance() .createPopupChooserBuilder(sources) .setRenderer(new CellRenderer()) .setTitle(useQualifiedImport ? PyPsiBundle.message("ACT.qualify.with.module") : PyPsiBundle.message("ACT.from.some.module.import")) .setItemChosenCallback(item -> { result.setResult(item); }) .setNamerForFiltering(o -> o.getPresentableText()) .createPopup() .showInBestPositionFor(dataContext)); return result; }