void (@NotNull AnActionEvent e) { final OrderEntry selectedEntry = myPanel.getSelectedEntry(); GlobalSearchScope mainScope = getScopeForOrderEntry(selectedEntry); LOG.assertTrue(mainScope != null); Map<GlobalSearchScope, OrderEntry> additionalScopes; ModulesProvider modulesProvider = myPanel.getModuleConfigurationState().getModulesProvider(); if (selectedEntry instanceof ModuleOrderEntry) { Module depModule = ((ModuleOrderEntry)selectedEntry).getModule(); LOG.assertTrue(depModule != null); Map<OrderEntry, OrderEntry> additionalDependencies = JavaProjectDependenciesAnalyzer.findExportedDependenciesReachableViaThisDependencyOnly(myPanel.getRootModel().getModule(), depModule, modulesProvider); additionalScopes = new LinkedHashMap<>(); for (Map.Entry<OrderEntry, OrderEntry> entry : additionalDependencies.entrySet()) { additionalScopes.put(getScopeForOrderEntry(entry.getKey()), entry.getValue()); } } else { additionalScopes = Collections.emptyMap(); } List<GlobalSearchScope> scopes = new ArrayList<>(additionalScopes.keySet()); scopes.add(mainScope); new AnalyzeDependenciesOnSpecifiedTargetHandler(myPanel.getProject(), new AnalysisScope(myPanel.getModuleConfigurationState().getCurrentRootModel().getModule()), GlobalSearchScope.union(scopes.toArray(GlobalSearchScope.EMPTY_ARRAY))) { @Override protected boolean shouldShowDependenciesPanel(@NotNull DependencyAnalysisResult result) { Set<GlobalSearchScope> usedScopes = ((MyAnalyzeResult)result).usedScopes; if (usedScopes.contains(mainScope)) { Messages.showInfoMessage(myProject, JavaUiBundle .message("message.text.dependencies.were.successfully.collected.in.0.toolwindow", ToolWindowId.ANALYZE_DEPENDENCIES), getTemplateText()); return true; } List<OrderEntry> usedEntries = usedScopes.stream().map(additionalScopes::get).filter(Objects::nonNull).distinct().collect(Collectors.toList()); if (usedEntries.isEmpty()) { final String message = JavaUiBundle.message("analyze.module.dependency.action.dialog.message.no.dependency.found", generateSkipImportsWarning()); if (Messages.showOkCancelDialog(myProject, message, getTemplateText(), CommonBundle.message("button.remove"), Messages.getCancelButton(), Messages.getWarningIcon()) == Messages.OK) { myPanel.getRootModel().removeOrderEntry(selectedEntry); } return false; } final String firstEntry = usedEntries.get(0).getPresentableName(); final List<OrderEntry> tailEntries; final String secondEntry; if (usedEntries.size() > 1) { tailEntries = usedEntries.subList(1, usedEntries.size() - 1); secondEntry = usedEntries.get(1).getPresentableName(); } else { tailEntries = Collections.emptyList(); secondEntry = null; } final String howeverExportedBy = JavaUiBundle.message("analyze.module.dependency.however.exported.by", firstEntry, secondEntry, StringUtil.decapitalize(selectedEntry.getPresentableName()), tailEntries.size(), usedEntries.size()); final String confirmReplace = JavaUiBundle.message("analyze.module.dependency.replace.dialog.confirm.replace", selectedEntry.getPresentableName(), usedEntries.size(), firstEntry); final String message = JavaUiBundle.message("analyze.module.dependency.replace.dialog.message", generateSkipImportsWarning(), howeverExportedBy, confirmReplace ); String[] options = {JavaUiBundle.message("button.text.replace"), JavaUiBundle.message("show.dependencies"), Messages.getCancelButton()}; return switch (Messages.showDialog(myProject, message, getTemplateText(), options, 0, Messages.getWarningIcon())) { case 0 -> { InlineModuleDependencyAction.inlineEntry(myPanel, selectedEntry, usedEntries::contains); yield false; } case 1 -> true; default -> false; }; } @Override protected @NotNull DependencyAnalysisResult createAnalysisResult() { return new MyAnalyzeResult(); } @Override protected void bgtPostAnalyze(DependencyAnalysisResult result) { super.bgtPostAnalyze(result); ((MyAnalyzeResult)result).usedScopes = ReadAction.compute(() -> findUsedScopes(result.getBuilders(), scopes)); } @Override protected boolean canStartInBackground() { return false; } }.analyze(); }