AnalysisScope (@NotNull DataContext dataContext, @NotNull Project project, Boolean acceptNonProjectDirectories) { // possible scopes: file, directory, package, project, module. Project projectContext = PlatformCoreDataKeys.PROJECT_CONTEXT.getData(dataContext); if (projectContext != null) { return new AnalysisScope(projectContext); } AnalysisScope analysisScope = AnalysisScopeUtil.KEY.getData(dataContext); if (analysisScope != null) { return analysisScope; } PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(dataContext); if (psiFile != null && psiFile.getManager().isInProject(psiFile)) { VirtualFile file = psiFile.getVirtualFile(); if (file != null && file.isValid() && file.getFileType() instanceof ArchiveFileType && acceptNonProjectDirectories) { VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(file); if (jarRoot != null) { PsiDirectory psiDirectory = psiFile.getManager().findDirectory(jarRoot); if (psiDirectory != null) { return new AnalysisScope(psiDirectory); } } } return new AnalysisScope(psiFile); } VirtualFile[] virtualFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext); if (virtualFiles != null) { // analyze on selection ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); if (virtualFiles.length == 1) { VirtualFile file = virtualFiles[0]; PsiDirectory psiDirectory = file.isValid() ? PsiManager.getInstance(project).findDirectory(file) : null; if (psiDirectory != null && (acceptNonProjectDirectories || psiDirectory.getManager().isInProject(psiDirectory))) { return new AnalysisScope(psiDirectory); } } Set<VirtualFile> files = new HashSet<>(); for (VirtualFile vFile : virtualFiles) { if (fileIndex.isInContent(vFile)) { files.add(vFile); } } return new AnalysisScope(project, files); } Module moduleContext = LangDataKeys.MODULE_CONTEXT.getData(dataContext); if (moduleContext != null) { return new AnalysisScope(moduleContext); } Module[] modulesArray = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext); if (modulesArray != null) { return new AnalysisScope(modulesArray); } return new AnalysisScope(project); }