@Override @Nullable public GlobalSearchScope getSearchScope() { GlobalSearchScope scope = null; Module[] modules = getConvertContextModules(); if (modules.length != 0) { PsiFile file = getFile(); file = file.getOriginalFile(); VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile != null) { ProjectFileIndex fileIndex = ProjectRootManager.getInstance(file.getProject()).getFileIndex(); boolean tests = fileIndex.isInTestSourceContent(virtualFile); for (Module module : modules) { if (scope == null) { scope = module.getModuleRuntimeScope(tests); } else { scope = scope.union(module.getModuleRuntimeScope(tests)); } } } } return scope; // ??? scope == null ? GlobalSearchScope.allScope(getProject()) : scope; ??? }
private static List<LanguageDefinition> collectLanguageDefinitions(final ConvertContext context) { final Project project = context.getProject(); final Collection<PsiClass> allLanguages = CachedValuesManager.getManager(project) .getCachedValue( project, () -> { final PsiClass languageClass = JavaPsiFacade.getInstance(project) .findClass(Language.class.getName(), GlobalSearchScope.allScope(project)); if (languageClass == null) { return Result.create( Collections.emptyList(), PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT); } final GlobalSearchScope projectProductionScope = GlobalSearchScopesCore.projectProductionScope(project); GlobalSearchScope allScope = projectProductionScope.union(ProjectScope.getLibrariesScope(project)); final Collection<PsiClass> allInheritors = ClassInheritorsSearch.search(languageClass, allScope, true).findAll(); return Result.create( allInheritors, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT); }); if (allLanguages.isEmpty()) { return Collections.emptyList(); } final List<LanguageDefinition> libraryDefinitions = collectLibraryLanguages(context, allLanguages); final GlobalSearchScope projectProductionScope = GlobalSearchScopesCore.projectProductionScope(project); final Collection<PsiClass> projectLanguages = ContainerUtil.filter( allLanguages, aClass -> PsiSearchScopeUtil.isInScope(projectProductionScope, aClass)); final List<LanguageDefinition> projectDefinitions = collectProjectLanguages(projectLanguages, libraryDefinitions); final List<LanguageDefinition> all = ContainerUtil.newArrayList(libraryDefinitions); all.addAll(projectDefinitions); return all; }