void (@NotNull List<PsiPackageAccessibilityStatement> sourceStatements, @NotNull List<PsiPackageAccessibilityStatement> targetStatements, @NotNull PsiPackage targetPackage, @NotNull List<PsiPackageAccessibilityStatement> statementsToCreate, @NotNull List<PsiPackageAccessibilityStatement> statementsToDelete) { List<PsiPackageAccessibilityStatement> allModuleStatements = new SmartList<>(sourceStatements); allModuleStatements.addAll(targetStatements); Map<PsiPackageAccessibilityStatement.Role, Set<String>> allModuleRefNamesByRole = new EnumMap<>(PsiPackageAccessibilityStatement.Role.class); for (PsiPackageAccessibilityStatement moduleStatement : allModuleStatements) { PsiPackageAccessibilityStatement.Role moduleStatementRole = moduleStatement.getRole(); Set<String> existingModuleRefNames = allModuleRefNamesByRole.get(moduleStatementRole); if (existingModuleRefNames == null) { allModuleRefNamesByRole.put(moduleStatementRole, new HashSet<>(moduleStatement.getModuleNames())); continue; } if (existingModuleRefNames.isEmpty()) continue; List<String> moduleRefNames = moduleStatement.getModuleNames(); // if module ref is empty then the package is exported/opened to any module, so we are extending a current visibility if (moduleRefNames.isEmpty()) { existingModuleRefNames.clear(); } else { existingModuleRefNames.addAll(moduleRefNames); } } removeRedundantModuleStatements(targetStatements, statementsToDelete, allModuleRefNamesByRole); statementsToCreate.addAll(createNewModuleStatements(targetPackage, allModuleRefNamesByRole)); }