IntelliJ Platform Plugin SDK
 
IntelliJ Platform Explorer

Rename Refactoring

Edit pageLast modified: 19 September 2024

The Rename refactoring operation is quite similar to that of Find Usages. It uses the same rules for locating the element to be renamed and the same index of words for finding the files that may have references to the element being renamed.

When the rename refactoring is performed, the method PsiNamedElement.setName() is called for the renamed element, and PsiReference.handleElementRename() is called for all references to the renamed element. These methods perform basically the same action: replace the underlying AST node of the PSI element with the node containing the new text entered by the user. Creating an entirely correct AST node from scratch is quite tricky. Thus, surprisingly, the easiest way to get the replacement node is to create a dummy file in the custom language so that it would contain the necessary node in its parse tree, build the parse tree and extract the required node from it.

Examples:

If a renamed reference extends PsiReferenceBase, renaming is performed by invoking the ElementManipulator.handleContentChange(), responsible for handling the content change and calculating the text range of reference inside the element.

To disable renaming for specific elements, implement com.intellij.openapi.util.Condition<T> for PsiElement of type T and register it in com.intellij.vetoRenameCondition extension point.