An Algorithm for Layout Preservation in Refactoring Transformations

June 03, 2011

We are adding support for definition of refactorings to Spoofax. An essential ingredient for refactorings is that the layout of the transformed program is minimally affected. In this paper, which has been accepted for the SLE 2011 conference, we present an algorithm that reconstruct the text of a program after refactoring, using the layout of the original program where possible.

Maartje de Jonge, Eelco Visser. An Algorithm for Layout Preservation in Refactoring Transformations. In Uwe Aßmann, Anthony M. Sloane, editors, Software Language Engineering, Fourth International Conference, SLE 2011, Braga, Portugal, July, 2011, Revised Selected Papers. Springer, 2012.

Abstract Transformations and semantic analysis for source-to-source transformations such as refactorings are most effectively implemented using an abstract representation of the source code. An intrinsic limitation of transformation techniques based on abstract syntax trees is the loss of layout, i.e. comments and whitespace. This is especially relevant in the context of refactorings, which produce source code for human consumption. In this paper, we present an algorithm for fully automatic source code reconstruction for source-to-source transformations. The algorithm preserves the layout and comments of the unaffected parts and reconstructs the indentation of the affected parts, using a set of clearly defined heuristic rules to handle comments.