Refactorings
Spoofax helps you to enrich your editor with refactorings. You can find the refactorings in the context menu of the file being edited.
Refactoring Specifications
The
EntityLang-Builders.esv file in the
editor directory defines the entries in the Refactor menu:
The given
refactoring specifies the "Rename" menu item, which is enabled in case an ID node is selected.The menu action is bind to the rename shortcut (Shift+Alt+R). After the user applies the rename refactoring, a dialog is prompted with an input field labeled "New name" that has the empty string as initial value.
The OK button of the dialog triggers the action defined with the
rename rule that we discuss in the next paragraph.
Refactoring Transformations
Refactorings are defined in Stratego. The
refactor.str file in the
trans directory defines the renaming refactoring for the entity language.
This rule follows a fixed interface for interoperability with the editor. The left-hand-side of the rule is a tuple of: the result of the user input dialog, the selected node, its tree position, the complete ast of the file, the file path and the project path. The right-hand-side is a tuple containing the refactoring output: a list of node changes, plus lists with errors and warnings that will be reported to the user. Errors and warnings are specified as a tuple of the offending language element (which location will be reported) and the error message itself.
Tip: multiple-file refactorings can be specified in the change list using the root nodes: [(ast-1-before, ast-1-after), (ast-2-before, ast-2-after), ...]
|