void (@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); }