public static void replaceFragment(@NotNull PsiFragment fragment, @NotNull @NonNls String newFragmentText) {
    final PsiElementFactory factory = JavaPsiFacade.getElementFactory(fragment.getProject());
    final PsiFragment newFragment = factory.createStringTemplateFragment(newFragmentText, fragment.getTokenType(), fragment);
    fragment.replace(newFragment);
  }
public static void replaceFragment(@NotNull PsiFragment fragment, @NotNull @NonNls String newFragmentText)