void (final Editor editor, final PsiClass targetClass, final PsiMethod method, boolean automatic, final Template template) { final int startOffset = method.getModifierList().getTextRange().getStartOffset(); final TextRange range = new TextRange(startOffset, method.getTextRange().getEndOffset()); editor.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), ""); editor.getCaretModel().moveToOffset(range.getStartOffset()); final Project project = targetClass.getProject(); TemplateEditingAdapter adapter = null; if (!automatic) { adapter = new TemplateEditingAdapter() { @Override public void templateFinished(@NotNull Template template, boolean brokenOff) { ApplicationManager.getApplication().runWriteAction(() -> { PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); PsiFile psi = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); PsiElement el = PsiTreeUtil.findElementOfClassAtOffset(psi, editor.getCaretModel().getOffset() - 1, PsiMethod.class, false); if (el != null) { PsiMethod method1 = PsiTreeUtil.getParentOfType(el, PsiMethod.class, false); if (method1 != null) { if (method1.findDeepestSuperMethods().length > 0) { GenerateMembersUtil.setupGeneratedMethod(method1); } CreateFromUsageUtils.setupEditor(method1, editor); } } }); } }; } TemplateManager.getInstance(project).startTemplate(editor, template, adapter); }