public static void startTemplate(@NotNull Project project, @NotNull PsiClass aClass, @NotNull Template template, @Nls @NotNull String text) {
    aClass = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(aClass);
    template.setToReformat(true);

    final Editor editor = CodeInsightUtil.positionCursor(project, Objects.requireNonNull(aClass).getContainingFile(), aClass);
    if (editor == null) return;

    Segment textRange = aClass.getTextRange();
    editor.getDocument().deleteString(textRange.getStartOffset(), textRange.getEndOffset());
    startTemplate(editor, template, project, null, text);
  }
public static void startTemplate(@NotNull Project project, @NotNull PsiClass aClass, @NotNull Template template, @Nls @NotNull String text)