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.
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.