List<PsiPackage> (final Project project) { return ReadAction.compute(() -> { final List<PsiPackage> packages = new ArrayList<>(); final PsiManager psiManager = PsiManager.getInstance(project); final String[] filters = getFilteredPackageNames(); if (filters.length == 0) { if (getFilteredClassNames().length > 0) return Collections.emptyList(); final PsiPackage defaultPackage = JavaPsiFacade.getInstance(psiManager.getProject()).findPackage(""); if (defaultPackage != null) { packages.add(defaultPackage); } } else { final List<String> nonInherited = new ArrayList<>(); for (final String filter : filters) { if (!isSubPackage(filters, filter)) { nonInherited.add(filter); } } for (String filter : nonInherited) { final PsiPackage psiPackage = JavaPsiFacade.getInstance(psiManager.getProject()).findPackage(filter); if (psiPackage != null) { packages.add(psiPackage); } } } return packages; }); }