@Nullable
  private static PsiModifierList createNewModifierList(@NotNull PsiModifierList oldModifierList, @NotNull String newModifiersText) {
    final PsiElementFactory factory = JavaPsiFacade.getElementFactory(oldModifierList.getProject());
    PsiElement parent = oldModifierList.getParent();
    if (parent instanceof PsiRequiresStatement) {
      String text = ("requires " + newModifiersText + " x;").trim();
      PsiRequiresStatement statement = (PsiRequiresStatement)factory.createModuleStatementFromText(text, oldModifierList);
      return statement.getModifierList();
    }
    else if (parent instanceof PsiClass) {
      String text = (newModifiersText + " class X {}").trim();
      PsiDeclarationStatement declarationStatement =
        (PsiDeclarationStatement)factory.createStatementFromText(text, oldModifierList);
      return ((PsiClass)declarationStatement.getDeclaredElements()[0]).getModifierList();
    }
    else {
      String text = (newModifiersText + " void x() {}").trim();
      PsiMethod method = factory.createMethodFromText(text, oldModifierList);
      return method.getModifierList();
    }
  }
@Nullable
  private static PsiModifierList createNewModifierList(@NotNull PsiModifierList oldModifierList, @NotNull String newModifiersText)