private static void rename(@NotNull PsiElement element,
                             @NotNull Project project,
                             PsiElement nameSuggestionContext,
                             @NotNull Collection<String> suggestedNames, 
                             Editor editor,
                             String defaultName,
                             RenamePsiElementProcessorBase processor) {
    PsiElement substituted = processor.substituteElementToRename(element, editor);
    if (substituted == null || !canRename(project, editor, substituted)) return;

    RenameRefactoringDialog dialog = processor.createDialog(project, substituted, nameSuggestionContext, editor);
    dialog.addSuggestedNames(suggestedNames);

    if (defaultName == null && ApplicationManager.getApplication().isUnitTestMode()) {
      String[] strings = dialog.getSuggestedNames();
      if (strings != null && strings.length > 0) {
        Arrays.sort(strings);
        defaultName = strings[0];
      }
      else {
        defaultName = "undefined"; // need to avoid show dialog in test
      }
    }

    if (defaultName != null) {
      try {
        dialog.performRename(defaultName);
      }
      finally {
        dialog.close(); // to avoid dialog leak
      }
    }
    else {
      dialog.show();
    }
  }
private static void rename(@NotNull PsiElement element,
                             @NotNull Project project,
                             PsiElement nameSuggestionContext,
                             @NotNull Collection<String> suggestedNames, 
                             Editor editor,
                             String defaultName,
                             RenamePsiElementProcessorBase processor)