public Result calculateResult(ExpressionContext context) {
   TemplateState templateState = TemplateManagerImpl.getTemplateState(context.getEditor());
   final TextResult insertedValue =
       templateState != null
           ? templateState.getVariableValue(InplaceRefactoring.PRIMARY_VARIABLE_NAME)
           : null;
   if (insertedValue != null) {
     if (!insertedValue.getText().isEmpty()) return insertedValue;
   }
   return new TextResult(myName);
 }
 public void restartInplaceIntroduceTemplate() {
   Runnable restartTemplateRunnable =
       () -> {
         final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
         if (templateState != null) {
           myEditor.putUserData(INTRODUCE_RESTART, true);
           try {
             final TextRange range = templateState.getCurrentVariableRange();
             if (range != null) {
               final TextResult inputText = templateState.getVariableValue(PRIMARY_VARIABLE_NAME);
               final String inputName = inputText != null ? inputText.getText() : null;
               final V variable = getVariable();
               if (inputName == null
                   || variable == null
                   || !isIdentifier(inputName, variable.getLanguage())) {
                 final String[] names =
                     suggestNames(isReplaceAllOccurrences(), getLocalVariable());
                 ApplicationManager.getApplication()
                     .runWriteAction(
                         () ->
                             myEditor
                                 .getDocument()
                                 .replaceString(
                                     range.getStartOffset(), range.getEndOffset(), names[0]));
               }
             }
             templateState.gotoEnd(true);
             try {
               myShouldSelect = false;
               startInplaceIntroduceTemplate();
             } finally {
               myShouldSelect = true;
             }
           } finally {
             myEditor.putUserData(INTRODUCE_RESTART, false);
           }
         }
         updateTitle(getVariable());
       };
   CommandProcessor.getInstance()
       .executeCommand(myProject, restartTemplateRunnable, getCommandName(), getCommandName());
 }