protected static void ensureName(IntroduceOperation operation) {
   if (operation.getName() == null) {
     final Collection<String> suggestedNames = operation.getSuggestedNames();
     if (suggestedNames.size() > 0) {
       operation.setName(suggestedNames.iterator().next());
     } else {
       operation.setName("x");
     }
   }
 }
 public PyAssignmentStatement createDeclaration(IntroduceOperation operation) {
   final Project project = operation.getProject();
   final PyExpression initializer = operation.getInitializer();
   InitializerTextBuilder builder = new InitializerTextBuilder();
   initializer.accept(builder);
   String assignmentText = operation.getName() + " = " + builder.result();
   PsiElement anchor =
       operation.isReplaceAll()
           ? findAnchor(operation.getOccurrences())
           : PsiTreeUtil.getParentOfType(initializer, PyStatement.class);
   return createDeclaration(project, assignmentText, anchor);
 }
  protected void performIntroduceWithDialog(IntroduceOperation operation) {
    final Project project = operation.getProject();
    if (operation.getName() == null) {
      PyIntroduceDialog dialog =
          new PyIntroduceDialog(project, myDialogTitle, myValidator, getHelpId(), operation);
      dialog.show();
      if (!dialog.isOK()) {
        return;
      }
      operation.setName(dialog.getName());
      operation.setReplaceAll(dialog.doReplaceAllOccurrences());
      operation.setInitPlace(dialog.getInitPlace());
    }

    PsiElement declaration = performRefactoring(operation);
    final Editor editor = operation.getEditor();
    editor.getCaretModel().moveToOffset(declaration.getTextRange().getEndOffset());
    editor.getSelectionModel().removeSelection();
  }