An Algorithm for Layout Preservation in Refactoring Transformations

  • Maartje de Jonge
  • Eelco Visser
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 6940)


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.


Abstract Syntax Concrete Syntax Text Fragment Origin Term Abstract Syntax Tree 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
  2. 2.
    The Spoofax language workbench (2010),
  3. 3.
    Bravenboer, M., Kalleberg, K.T., Vermaas, R., Visser, E.: Stratego/XT 0.17. A language and toolset for program transformation. Science of Computer Programming 72(1-2), 52–70 (2008)MathSciNetCrossRefGoogle Scholar
  4. 4.
    de Jonge, M.: A pretty-printer for every occasion. In: The International Symposium on Constructing Software Engineering Tools (CoSET 2000), pp. 68–77. University of Wollongong, Australia (2000)Google Scholar
  5. 5.
    de Jonge, M.: Pretty-printing for software reengineering. In: ICSM 2002: Proceedings of the International Conference on Software Maintenance (ICSM 2002), p. 550. IEEE Computer Society, Washington, DC (2002)CrossRefGoogle Scholar
  6. 6.
    Van de Vanter, M.L.: Preserving the documentary structure of source code in language-based transformation tools. In: 1st IEEE International Workshop on Source Code Analysis and Manipulation (SCAM 2001), November 10, pp. 133–143. IEEE Computer Society, Florence (2001)Google Scholar
  7. 7.
    Dean, T.R., Cordy, J.R., Schneider, K.A., Malton, A.J.: Using design recovery techniques to transform legacy systems. In: ICSM 2001: Proceedings of the IEEE International Conference on Software Maintenance (ICSM 2001), p. 622. IEEE Computer Society, Washington, DC (2001)CrossRefGoogle Scholar
  8. 8.
    Foster, J.N., Greenwald, M.B., Moore, J.T., Pierce, B.C., Schmitt, A.: Combinators for bidirectional tree transformations: A linguistic approach to the view-update problem. ACM Trans. Program. Lang. Syst. 29(3) (2007)Google Scholar
  9. 9.
    Fowler, M.: Refactoring: Improving the Design of Existing Code. Addison Wesley (1999)Google Scholar
  10. 10.
    Fowler, M.: Language workbenches: The killer-app for domain specific languages? (2005)Google Scholar
  11. 11.
    Hemel, Z., Visser, E.: Programming the Mobile Web with Mobl. Technical Report 2011-01, Delft University of Technology (January 2011)Google Scholar
  12. 12.
    Kats, L.C.L., Visser, E.: The Spoofax language workbench. Rules for declarative specification of languages and ides. In: Rinard, M. (ed.) Proceedings of the 25th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2010, Reno, NV, USA, October 17-21 (2010)Google Scholar
  13. 13.
    Kitlei, R., Lóvei, L., Nagy, T., Horváth, Z., Kozsik, T.: Layout preserving parser for refactoring in Erlang. Acta Electrotechnica et Informatica 9(3), 54–63 (2009)Google Scholar
  14. 14.
    Kort, J., Lämmel, R.: Parse-tree annotations meet re-engineering concerns. In: Proceedings of Third IEEE International Workshop on Source Code Analysis and Manipulation (September 2003)Google Scholar
  15. 15.
    Li, H., Thompson, S.: A comparative study of refactoring Haskell and Erlang programs. In: Penta, M.D., Moonen, L. (eds.) Sixth IEEE International Workshop on Source Code Analysis and Manipulation (SCAM 2006), pp. 197–206. IEEE (September 2006)Google Scholar
  16. 16.
    Li, H., Thompson, S., Orosz, G., Toth, M.: Refactoring with Wrangler, updated: Data and process refactorings, and integration with Eclipse. In: Horvath, Z., Teoh, T. (eds.) Proceedings of the Seventh ACM SIGPLAN Erlang Workshop, p. 12. ACM Press (September 2008)Google Scholar
  17. 17.
    Li, H., Thompson, S., Reinke, C.: The Haskell Refactorer: HaRe, and its API. In: Boyland, J., Hedin, G. (eds.) Proceedings of the 5th Workshop on Language Descriptions, Tools and Applications (LDTA 2005) (April 2005)Google Scholar
  18. 18.
    Lohmann, W., Riedewald, G.: Towards automatical migration of transformation rules after grammar extension. In: CSMR 2003: Proceedings of the Seventh European Conference on Software Maintenance and Reengineering, p. 30. IEEE Computer Society, Washington, DC (2003)Google Scholar
  19. 19.
    Malton, A., Schneider, K.A., Cordy, J.R., Dean, T.R., Cousineau, D., Reynolds, J.: Processing software source text in automated design recovery and transformation. In: Proc. International Workshop on Program Comprehension (IWPC 2001), pp. 127–134. IEEE Press (2001)Google Scholar
  20. 20.
    van den Brand, M., Vinju, J.: Rewriting with layout. In: Kirchner, C., Dershowitz, N. (eds.) Proceedings of RULE (2000)Google Scholar
  21. 21.
    van den Brand, M., Visser, E.: Generation of formatters for context-free languages. ACM Transactions on Software Engineering Methodology 5(1), 1–41 (1996)CrossRefGoogle Scholar
  22. 22.
    van Deursen, A., Klint, P., Tip, F.: Origin tracking. J. Symb. Comput. 15(5-6), 523–545 (1993)zbMATHCrossRefGoogle Scholar
  23. 23.
    Visser, E.: Syntax Definition for Language Prototyping. PhD thesis, University of Amsterdam (September 1997)Google Scholar
  24. 24.
    Visser, E.: WebDSL: A Case Study in Domain-Specific Language Engineering. In: Lämmel, R., Visser, J., Saraiva, J. (eds.) GTTSE 2007. LNCS, vol. 5235, pp. 291–373. Springer, Heidelberg (2008)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2012

Authors and Affiliations

  • Maartje de Jonge
    • 1
  • Eelco Visser
    • 1
  1. 1.Dept. of Software TechnologyDelft University of TechnologyThe Netherlands

Personalised recommendations