List<PsiPackageAccessibilityStatement> (@NotNull PsiPackage targetPackage, @NotNull Map<PsiPackageAccessibilityStatement.Role, Set<String>> allModuleRefNamesByRole) { List<PsiPackageAccessibilityStatement> result = new SmartList<>(); PsiElementFactory psiFactory = PsiElementFactory.getInstance(myProject); CodeStyleManager styleManager = CodeStyleManager.getInstance(myProject); for (var entry : allModuleRefNamesByRole.entrySet()) { String moduleStatementText = formModuleStatementText(entry.getKey(), new TreeSet<>(entry.getValue()), targetPackage.getQualifiedName()); PsiPackageAccessibilityStatement moduleStatement = (PsiPackageAccessibilityStatement)psiFactory.createModuleStatementFromText(moduleStatementText, targetPackage); result.add((PsiPackageAccessibilityStatement)styleManager.reformat(moduleStatement)); } return result; }