21. Rename Refactoring

The rename refactoring operation is implemented based on current Xtext’s rename refactoring implementation. However, lots of customization have been done in order to make Rename Refactoring work for N4JS. In order to understand N4JS customization, it is imperative to understand how Xtext implements rename refactoring. In this chapter, we will focus on Xtext’s architecture for rename refactoring. Additionally, we will point to the components that have been customized for N4JS.

21.1. Rename Refactoring UI interaction

Xtext’s implementation allows rename refactoring be in either one of two modes (1) Direct refactoring mode (3) Refactoring with dialog mode. Diagram Direct Rename Refactoring UI interaction shows the UI interaction in direct refactoring mode.

title-

In this diagram, the classes in yellow are customized by N4JS implementation to handle N4JS-specific characteristics.

  • DefaultRenameElementHandler: Our custom N4JS implementation converts the selected element to be renamed into its corresponding TModule element.

  • ILinkedPositionGroupCalculator: This class is responsible for calculating locations of names to be changed during linked edit mode. We need to provide a custom N4JS implementation to handle composed elements.

  • RenameElementProcessor: We need to provide a custom N4JS implementation to add N4JS-specific validation of conditions, e.g. checking name conflicts etc.

The key class for creating updates of a declaration and its associated references is RenameElementProcessor. In the following section, we will see how this class interacts with other classes to achieve this.

21.2. RenameElementProcessor interaction

Diagram RenameElementProcessor interaction shows the interaction of RenameElementProcessor and other classes to create changes for both declaration and references during rename refactoring.

title-

As seen in the diagram, there are two stages of creating updates:

  1. Creating updates for declaration is done by IRenameStrategy and

  2. Creating updates for references is done by ReferenceUpdateDispatcher. ReferenceUpdateDispatcher in turn delegates the finding of references to IReferenceFinder.

The text edits for changing the definition and the references are accumulated by an IRefactoringUpdateAcceptor.

The classes in yellow are customized by N4JS implementation.

  • IRenameStrategy: the custom N4JS implementation creates updates for constituent members of composed elements.

  • IReferenceFinder: the custom N4JS implementation used for finding references of a declaration.

  • RefactoringCrossReferenceSerializer: custom N4JS implementation to retrieve the updated name for cross references. For some unknown reason, the default implementation does not work correctly.

Quick Links