void (@NotNull PsiFile psiFile, @NotNull List<? super PsiElement> outElements, @NotNull Set<? super String> outDialects) { FileViewProvider viewProvider = psiFile.getViewProvider(); Set<Language> processedLanguages = new SmartHashSet<>(); // we hope that injected file here is small enough for PsiRecursiveElementVisitor PsiElementVisitor visitor = new PsiRecursiveElementVisitor() { @Override public void visitElement(@NotNull PsiElement element) { ProgressManager.checkCanceled(); PsiElement child = element.getFirstChild(); while (child != null) { outElements.add(child); child.accept(this); appendDialects(child, processedLanguages, outDialects); child = child.getNextSibling(); } } }; for (Language language : viewProvider.getLanguages()) { PsiFile psiRoot = viewProvider.getPsi(language); if (psiRoot == null || !HighlightingLevelManager.getInstance(psiFile.getProject()).shouldInspect(psiRoot)) { continue; } outElements.add(psiRoot); psiRoot.accept(visitor); appendDialects(psiRoot, processedLanguages, outDialects); } }