void (@NotNull List<PsiPackageAccessibilityStatement> sourceStatements, @NotNull List<PsiPackageAccessibilityStatement> statementsToDelete, @NotNull Map<PsiPackageAccessibilityStatement.Role, Set<String>> allModuleRefNamesByRole) { Map<PsiPackageAccessibilityStatement.Role, PsiPackageAccessibilityStatement> moduleStatementsByRole = new EnumMap<>( PsiPackageAccessibilityStatement.Role.class); for (PsiPackageAccessibilityStatement sourceStatement : sourceStatements) { moduleStatementsByRole.put(sourceStatement.getRole(), sourceStatement); } for (var entry : moduleStatementsByRole.entrySet()) { PsiPackageAccessibilityStatement.Role role = entry.getKey(); Set<String> moduleRefNames = allModuleRefNamesByRole.get(role); PsiPackageAccessibilityStatement moduleStatement = entry.getValue(); if (moduleRefNames.equals(new HashSet<>(moduleStatement.getModuleNames()))) { allModuleRefNamesByRole.remove(role); } else { statementsToDelete.add(moduleStatement); } } }