Creating a new Refactoring

I am trying to create an entirely new Refactoring in a plugin.

The article here explains how this is done in Eclipse, which is by creating a subclass: "Refactoring Class: The refactoring class is the principal component of a refactoring and implements most of the refactoring-specific functionality. It is required to extend the abstract class

" (this is under the Behind the Scenes of Refactorings: Architecture and Design header).

Is there a similar article, but for IntelliJ?

It seems that in IntelliJ, each Refactoring is a completely separate entity instead.

(Please note, I have found plenty of documentation on how to support existing Refactorings for custom languages. This is not my goal. I wish to create a completely new Refactoring with new functionality that works for Java.)

Comment actions Permalink

As I understand it from this plugin, these are the general steps:
1. Create a CustomAction that extends AnAction
     1.1. Register the CustomAction in plugin.xml under actions
     1.2. Find Project and PsiElements to work with
     1.3. The CustomAction adds content to tool window in form of a CustomPanel
          1.3.1. Sends Project and PsiElements to the CustomPanel
2. Create a CustomPanel that extends JPanel
     2.1. Finds Module
     2.2. Calls run method of functional class
          2.2.1. Passes through the PsiElements and Module to the functional class
3. Create class which performs functions of refactoring
     3.1. Doesn't extend anything (unlike in Eclipse)
     3.2. Modifies PsiElements somehow in order to perform the refactoring

Is this the right idea? Again, if there's some sort of article, documentation, or tutorial for this, please point me to it.

Comment actions Permalink

There is no single correct sequence of steps. The unchain plugin happens to need a panel for selecting the things to move, so it has one. Other refactorings have other types of UI - a dialog, or a sequence of dialogs, or an in-place popup in the editor, or no UI at all. Some refactorings are invoked from the menu, and therefore implement AnAction. Others are invoked from the Alt-Enter popup, and therefore implement IntentionAction. Everything depends on how you want your refactoring to work.

Also because of this, there is no tutorial - all refactorings are different.

Comment actions Permalink

Thanks Dmitry. So there is no common superclass for a refactoring, a programmer must choose how to invoke it via the GUI and then the actual class that performs the functions of the refactoring does not extend anything.


Please sign in to leave a comment.