void (final PsiClass targetClass, final Project project, final Object expectedTypes, final PsiField field, final boolean createConstantField, final PsiElement context) { final PsiFile targetFile = targetClass.getContainingFile(); final Editor newEditor = CodeInsightUtil.positionCursor(project, targetFile, field); if (newEditor == null) return; Template template = CreateFieldFromUsageHelper.setupTemplate(field, expectedTypes, targetClass, newEditor, context, createConstantField); startTemplate(newEditor, template, project, new TemplateEditingAdapter() { @Override public void templateFinished(@NotNull Template template, boolean brokenOff) { PsiDocumentManager.getInstance(project).commitDocument(newEditor.getDocument()); final int offset = newEditor.getCaretModel().getOffset(); final PsiField psiField = PsiTreeUtil.findElementOfClassAtOffset(targetFile, offset, PsiField.class, false); if (psiField != null) { ApplicationManager.getApplication().runWriteAction(() -> { CodeStyleManager.getInstance(project).reformat(psiField); }); newEditor.getCaretModel().moveToOffset(psiField.getTextRange().getEndOffset() - 1); } } }); }