Apparent Intellij bugs when listening to refactorings

Hello,

Refactoring events (com.intellij.refactoring.listeners.RefactoringEventListener) are not fired for the following refactorings:

  • local variable rename (although field, method and class renamings are fired)
  • extract method undo (other undos seem fine)


I use the following code to listen to events:

project.getMessageBus().connect().subscribe(RefactoringEventListener.REFACTORING_EVENT_TOPIC, new RefactoringEventListener() {

            @Override

            public void refactoringStarted(@NotNull String s, @Nullable RefactoringEventData refactoringEventData) {

                System.out.println("started: " + s);

            }


            @Override

            public void refactoringDone(@NotNull String s, @Nullable RefactoringEventData refactoringEventData) {

                System.out.println("ended: " + s);

            }


            @Override

            public void conflictsDetected(@NotNull String s, @NotNull RefactoringEventData refactoringEventData) {


            }


            @Override

            public void undoRefactoring(@NotNull String s) {

                System.out.println("undone:" + s);

            }

        });

Am I doing something wrong or is the refactoring notification mechanism buggy?

3 comments

The mechanism is not buggy; it functions as designed. Its purpose is to enable updating external settings (run configurations, project settings etc.) when classes or methods are moved or renamed. Since external settings never depend on names of local variables, it does not send any notifications for local variable renames. And of course, the undoRefactoring() notification is sent only for those refactorings about which the listener is capable of notifying; it would be extremely weird to have a notification for undoing an extract method refactoring but not for performing it in the first place.

0

So then the mistake was that I took that class at face value as a listener to all refactorings, as its name and methods suggested.

How can I listen to all refactoring executions in IntelliJ? My best bet up until now was the RefactoringEventListener.
I need to log all refactoring starts, refactoring ends and refactoring undos.
This is the equivalent Eclipse snippet: RefactoringHistoryService.getInstance().addExecutionListener(new IRefactoringExecutionListener(){ ... })

Thanks

0

So, is there then a way to reliably listen to all refactoring starts, ends and undos?
I've been looking through the source code but I can't find anything else.

0

Please sign in to leave a comment.