boolean (DataContext dataContext) { final Project project = CommonDataKeys.PROJECT.getData(dataContext); final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); if (project == null || view == null) { return false; } final PsiDirectory[] directories = view.getDirectories(); if (directories.length == 0) { return false; } final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); final JavaDirectoryService directoryService = JavaDirectoryService.getInstance(); final PsiNameHelper nameHelper = PsiNameHelper.getInstance(project); for (PsiDirectory directory : directories) { if (projectFileIndex.isUnderSourceRootOfType(directory.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && PsiUtil.isLanguageLevel5OrHigher(directory)) { final PsiPackage aPackage = directoryService.getPackage(directory); if (aPackage != null) { final String qualifiedName = aPackage.getQualifiedName(); if (StringUtil.isEmpty(qualifiedName) || nameHelper.isQualifiedName(qualifiedName)) { return true; } } } } return false; }