void (@NotNull final Processor<? super Usage> processor) { Runnable runnable = () -> { final List<?> list; if (myResult.isEmpty()) { try { list = (List<?>)myXPath.selectNodes(myContextNode); } catch (JaxenException e) { LOG.debug(e); Messages.showMessageDialog(myContextNode.getProject(), e.getMessage(), XPathBundle.message("dialog.title.xpath.error"), Messages.getErrorIcon()); return; } } else { list = myResult; } final int size = list.size(); final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); indicator.setText(XPathBundle.message("progress.text.collecting.matches")); list.sort((Comparator)(o1, o2) -> { indicator.checkCanceled(); if (o1 instanceof PsiElement && o2 instanceof PsiElement) { return ((PsiElement)o1).getTextRange().getStartOffset() - ((PsiElement)o2).getTextRange().getStartOffset(); } else { return String.valueOf(o1).compareTo(String.valueOf(o2)); } }); for (int i = 0; i < size; i++) { indicator.checkCanceled(); Object o = list.get(i); if (o instanceof PsiElement element) { processor.process(new UsageInfo2UsageAdapter(new UsageInfo(element))); indicator.setText2(element.getContainingFile().getName()); } indicator.setFraction(i / (double)size); } list.clear(); }; ApplicationManager.getApplication().runReadAction(runnable); }