boolean (@NotNull PsiDirectory directory) { ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myManager.getProject()).getFileIndex(); VirtualFile virtualFile = directory.getVirtualFile(); PackageIndex packageIndex = PackageIndex.getInstance(myManager.getProject()); return fileIndex.isUnderSourceRootOfType(virtualFile, JavaModuleSourceRootTypes.SOURCES) && packageIndex.getPackageNameByDirectory(virtualFile) != null; }