public static void doRename(
      final PsiElement element,
      String newName,
      UsageInfo[] usages,
      final Project project,
      @Nullable final RefactoringElementListener listener)
      throws IncorrectOperationException {
    final RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(element);
    final String fqn =
        element instanceof PsiFile
            ? ((PsiFile) element).getVirtualFile().getPath()
            : CopyReferenceAction.elementToFqn(element);
    if (fqn != null) {
      UndoableAction action =
          new BasicUndoableAction() {
            public void undo() throws UnexpectedUndoException {
              if (listener instanceof UndoRefactoringElementListener) {
                ((UndoRefactoringElementListener) listener).undoElementMovedOrRenamed(element, fqn);
              }
            }

            @Override
            public void redo() throws UnexpectedUndoException {}
          };
      UndoManager.getInstance(project).undoableActionPerformed(action);
    }
    processor.renameElement(element, newName, usages, listener);
  }