Retaining comments when refactoring code

Today's software developer depends on automated refactoring tools. While implementing such refactoring tools based on the Eclipse platform for a variety of languages, we faced the problem that carefully crafted formatting and comments can disappear when refactoring source code. This is annoying. Therefore, a useful refactoring tool should keep comments and move them along with the source code they belong to. We present different approaches on how to retain comments when refactoring source code. Usually comments are not present in an abstract syntax tree (AST) used by an integrated development environment (IDE). We achieve comment retention by associating them with nodes in an AST. The different attempts on gathering comments and implementing that association are shown and evaluated. Details of comment handling in different refactoring plug-ins that we have implemented for Eclipse, are given as well as a brief comparison with comment handling when refactoring with the Eclipse Java Development Tools (JDT). We hope, that this paper enables others to implement comment-preserving refactoring tools for more languages and IDEs. Every programmer, language and IDE deserves good refactoring support or they might become endangered.

[1]  M. F.,et al.  Bibliography , 1985, Experimental Gerontology.

[2]  Peter Sommerlad,et al.  Refactoring support for the C++ development tooling , 2007, OOPSLA '07.

[3]  Peter Sommerlad,et al.  Ruby refactoring plug-in for eclipse , 2007, OOPSLA '07.

[4]  Jonathan Grudin,et al.  Development tools , 1995 .

[5]  David F. Bacon,et al.  Companion to the 22nd ACM SIGPLAN conference on Object-oriented programming systems and applications companion , 2007, OOPSLA 2007.

[6]  Martin Fowler,et al.  Refactoring - Improving the Design of Existing Code , 1999, Addison Wesley object technology series.