public static void replaceType(@NotNull String newTypeText, @NotNull PsiTypeElement typeElement) throws IncorrectOperationException {
    final Project project = typeElement.getProject();
    final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
    final PsiType newType = factory.createTypeFromText(newTypeText, null);
    final PsiTypeElement newTypeElement = factory.createTypeElement(newType);
    final PsiElement insertedElement = typeElement.replace(newTypeElement);
    final PsiElement shortenedElement = JavaCodeStyleManager.getInstance(project).shortenClassReferences(insertedElement);
    CodeStyleManager.getInstance(project).reformat(shortenedElement);
  }
public static void replaceType(@NotNull String newTypeText, @NotNull PsiTypeElement typeElement)