Refactorings
Spoofax
--
MaartjeDeJonge - 25 Nov 2011
Refactorings
Spoofax helps you to enrich your editor with refactorings. You can find 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 context menu:
The given
refactoring specifies the "Rename" menu item, bind to the rename shortcut (Shift+Alt+R). The menu action is enabled in case an ID node is selected. 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.
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), ...]
|
Errors and warnings are specified as a tuple of the offending language element (which location will be reported) and the error message itself.