public static void replaceStatement(@NotNull String newStatement, @NotNull PsiStatement statement) throws IncorrectOperationException {
    final Project project = statement.getProject();
    final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
    final PsiStatement newCall = factory.createStatementFromText(newStatement, null);
    final PsiElement insertedElement = statement.replace(newCall);
    final PsiElement shortenedElement = JavaCodeStyleManager.getInstance(project).shortenClassReferences(insertedElement);
    CodeStyleManager.getInstance(project).reformat(shortenedElement);
  }
public static void replaceStatement(@NotNull String newStatement, @NotNull PsiStatement statement)