PsiDirectory[] (Project project, String rootPackage, final GlobalSearchScope scope) { final PsiManager manager = PsiManager.getInstance(project); Query<VirtualFile> query = getDirectoriesByPackageName(rootPackage, true, project); query = new FilteredQuery<>(query, scope::contains); List<PsiDirectory> directories = ContainerUtil.mapNotNull(query.findAll(), manager::findDirectory); return directories.toArray(PsiDirectory.EMPTY_ARRAY); }