List<Usage> (@NotNull Project project, @NotNull PsiFile psiFile, @NotNull FindModel findModel) { if (project.isDisposed()) { return null; } psiFile = (PsiFile)psiFile.getNavigationElement(); if (psiFile == null) { return null; } Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile); if (document == null) return null; CharSequence text = document.getCharsSequence(); int textLength = document.getTextLength(); FindManager findManager = FindManager.getInstance(project); findModel.setForward(true); // when find all there is no diff in direction int offset = 0; VirtualFile virtualFile = psiFile.getVirtualFile(); final List<Usage> usages = new ArrayList<>(); while (offset < textLength) { FindResult result = findManager.findString(text, offset, findModel, virtualFile); if (!result.isStringFound()) break; usages.add(new UsageInfo2UsageAdapter(new UsageInfo(psiFile, result.getStartOffset(), result.getEndOffset()))); final int prevOffset = offset; offset = result.getEndOffset(); if (prevOffset == offset) { // for regular expr the size of the match could be zero -> could be infinite loop in finding usages! ++offset; } } return usages; }