AnalysisScope (DataContext dataContext) { //Possible scopes: package, project, module. Project projectContext = PlatformCoreDataKeys.PROJECT_CONTEXT.getData(dataContext); if (projectContext != null) { return null; } Module moduleContext = LangDataKeys.MODULE_CONTEXT.getData(dataContext); if (moduleContext != null) { return null; } final Module [] modulesArray = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext); if (modulesArray != null && modulesArray.length > 0) { return new AnalysisScope(modulesArray); } PsiElement psiTarget = CommonDataKeys.PSI_ELEMENT.getData(dataContext); if (psiTarget instanceof PsiDirectory psiDirectory) { if (!psiDirectory.getManager().isInProject(psiDirectory)) return null; return new AnalysisScope(psiDirectory); } if (psiTarget instanceof PsiPackage pack) { PsiDirectory[] dirs = pack.getDirectories(GlobalSearchScope.projectScope(pack.getProject())); if (dirs.length == 0) return null; return new JavaAnalysisScope(pack, PlatformCoreDataKeys.MODULE.getData(dataContext)); } return null; }