@Override
        public void templateFinished(@NotNull Template template, boolean brokenOff) {
          Runnable action = () -> {
            PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());

            CaretModel caretModel = editor.getCaretModel();
            PsiElement elementAt = file.findElementAt(caretModel.getOffset());
            PsiDeclarationStatement declarationStatement = PsiTreeUtil.getParentOfType(elementAt, PsiDeclarationStatement.class);
            if (declarationStatement != null) {
              caretModel.moveToOffset(declarationStatement.getTextRange().getEndOffset());
            }
            new EnterAction().getHandler().execute(editor, null, null);
          };
          if (file.isPhysical()) {
            ApplicationManager.getApplication().runWriteAction(action);
          } else {
            action.run();
          }
        }
@Override
        public void templateFinished(@NotNull Template template, boolean brokenOff)