CommonProblemDescriptor[] (@NotNull RefEntity refEntity, @NotNull AnalysisScope scope, @NotNull InspectionManager manager, @NotNull final GlobalInspectionContext globalContext) { if (refEntity instanceof RefModule refModule){ final Module module = refModule.getModule(); final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); boolean onlyGeneratedSources = true; for (ContentEntry entry : moduleRootManager.getContentEntries()) { for (SourceFolder folder : entry.getSourceFolders()) { if (!JavaProjectRootsUtil.isForGeneratedSources(folder)) { onlyGeneratedSources = false; break; } } } if (onlyGeneratedSources) return null; final OrderEntry[] declaredDependencies = moduleRootManager.getOrderEntries(); final List<CommonProblemDescriptor> descriptors = new ArrayList<>(); final Set<Module> modules = refModule.getUserData(UnnecessaryModuleDependencyAnnotator.DEPENDENCIES); final List<Module> candidates = new ArrayList<>(); for (final OrderEntry entry : declaredDependencies) { if (entry instanceof ModuleOrderEntry && ((ModuleOrderEntry)entry).getScope() != DependencyScope.RUNTIME && !((ModuleOrderEntry)entry).isExported()) { final Module dependency = ((ModuleOrderEntry)entry).getModule(); if (dependency == null || modules != null && modules.remove(dependency)) { continue; } candidates.add(dependency); } } for (Module dependency : candidates) { if (modules != null) { HashSet<Module> outs = new HashSet<>(); OrderEnumerator.orderEntries(dependency) .withoutSdk() .exportedOnly() .recursively() .forEachModule(outs::add); if (ContainerUtil.intersects(modules, outs)) continue; } descriptors.add(createDescriptor(scope, manager, module, dependency)); } return descriptors.isEmpty() ? null : descriptors.toArray(CommonProblemDescriptor.EMPTY_ARRAY); } return null; }