Stream<PsiElement> () { PsiManager psiManager = PsiManager.getInstance(myProject); final LanguageCompilerRefAdapter adapter = Objects.requireNonNull(LanguageCompilerRefAdapter.findAdapter(mySearchFileType)); return myCandidatePerFile .entrySet() .stream() .filter(e -> ReadAction.compute(() -> mySearchScope.contains(e.getKey()))) .flatMap(e -> { final VirtualFile file = e.getKey(); final SearchId[] definitions = e.getValue(); final PsiElement[] hierarchyChildren = ReadAction.compute(() -> { final PsiFileWithStubSupport psiFile = (PsiFileWithStubSupport)psiManager.findFile(file); return mySearchType.performSearchInFile(definitions, myBaseClass, psiFile, adapter); }); if (hierarchyChildren.length == definitions.length) { return Stream.of(hierarchyChildren); } else { LOG.assertTrue(mySearchType == CompilerHierarchySearchType.DIRECT_INHERITOR, "Should not happens for functional expression search"); return Stream.of(hierarchyChildren).filter(c -> ReadAction.compute(() -> adapter.isDirectInheritor(c, myBaseClass))); } }); }