void (@NotNull AnActionEvent e) { InspectionResultsView view = getView(e); Set<PsiFile> files = new HashSet<>(); for (RefEntity entity : Objects.requireNonNull(view).getTree().getSelectedElements()) { if (entity instanceof RefElement && entity.isValid()) { final PsiElement element = ((RefElement)entity).getPsiElement(); final PsiFile file = element.getContainingFile(); files.add(file); } } boolean useModule = true; Module module = null; for (PsiFile file : files) { final Module currentFileModule = ModuleUtilCore.findModuleForPsiElement(file); if (currentFileModule != null) { if (module == null) { module = currentFileModule; } else if (currentFileModule != module) { useModule = false; break; } } else { useModule = false; break; } } final PsiElement context; final AnalysisScope scope; switch (files.size()) { case 0 -> { context = null; scope = view.getScope(); } case 1 -> { final PsiFile theFile = ContainerUtil.getFirstItem(files); LOG.assertTrue(theFile != null); context = theFile; scope = new AnalysisScope(theFile); } default -> { context = null; scope = new AnalysisScope(view.getProject(), ContainerUtil.map(files, PsiFile::getVirtualFile)); } } RunInspectionIntention.selectScopeAndRunInspection(Objects.requireNonNull(getToolWrapper(e)).getShortName(), scope, useModule ? module : null, context, view.getProject()); }