String (PsiModifierList list, String newVisibility) { final String oldVisibility = VisibilityUtil.getVisibilityModifier(list); List<String> modifierKeywords = new ArrayList<>(ContainerUtil.map(PsiTreeUtil.findChildrenOfType(list, PsiKeyword.class), PsiElement::getText)); if (!oldVisibility.equals(newVisibility)) { if (oldVisibility.equals(PsiModifier.PACKAGE_LOCAL)) { modifierKeywords.add(0, PsiModifier.PACKAGE_LOCAL); } if (newVisibility.equals(PsiModifier.PACKAGE_LOCAL)) { modifierKeywords.remove(oldVisibility); } else { modifierKeywords.replaceAll(m -> m.equals(oldVisibility) ? newVisibility : m); } } return String.join(" ", modifierKeywords); }