@Override
 protected void moveOffsetAfter(boolean success) {
   if (getLocalVariable() != null && getLocalVariable().isValid()) {
     myEditor.getCaretModel().moveToOffset(getLocalVariable().getTextOffset());
     myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
   } else if (getExprMarker() != null) {
     final RangeMarker exprMarker = getExprMarker();
     if (exprMarker.isValid()) {
       myEditor.getCaretModel().moveToOffset(exprMarker.getStartOffset());
       myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
     }
   }
   super.moveOffsetAfter(success);
   if (myLocalMarker != null && !isRestart()) {
     myLocalMarker.dispose();
   }
   if (success) {
     performPostIntroduceTasks();
     final String refactoringId = getRefactoringId();
     if (refactoringId != null) {
       final RefactoringEventData afterData = new RefactoringEventData();
       afterData.addElement(getVariable());
       myProject
           .getMessageBus()
           .syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC)
           .refactoringDone(refactoringId, afterData);
     }
   }
 }
  @Override
  protected void releaseResources() {
    super.releaseResources();
    if (myPreview == null) return;

    EditorFactory.getInstance().releaseEditor(myPreview);
    myPreview = null;
  }
  protected boolean ensureValid() {
    final String newName = getInputName();
    if (getLocalVariable() == null && myExpr == null
        || newName == null
        || getLocalVariable() != null && !getLocalVariable().isValid()
        || myExpr != null && !myExpr.isValid()) {
      super.moveOffsetAfter(false);
      return false;
    }
    if (getLocalVariable() != null) {
      new WriteCommandAction(myProject, getCommandName(), getCommandName()) {
        @Override
        protected void run(@NotNull Result result) throws Throwable {
          getLocalVariable().setName(myLocalName);
        }
      }.execute();
    }

    if (!isIdentifier(
        newName, myExpr != null ? myExpr.getLanguage() : getLocalVariable().getLanguage()))
      return false;
    return true;
  }
 @Override
 public void finish(boolean success) {
   myFinished = true;
   final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
   if (templateState != null) {
     myEditor.putUserData(ACTIVE_INTRODUCE, null);
   }
   if (myDocumentAdapter != null) {
     myEditor.getDocument().removeDocumentListener(myDocumentAdapter);
   }
   if (myBalloon == null) {
     releaseIfNotRestart();
   }
   super.finish(success);
   if (success) {
     PsiDocumentManager.getInstance(myProject).commitAllDocuments();
     final V variable = getVariable();
     if (variable == null) {
       return;
     }
     restoreState(variable);
   }
 }
 @Override
 protected void showBalloon() {
   if (myFinished) return;
   super.showBalloon();
 }
 @Override
 protected void navigateToAlreadyStarted(Document oldDocument, int exitCode) {
   finish(true);
   super.navigateToAlreadyStarted(oldDocument, exitCode);
 }