Sound and extensible renaming for java

Descriptive names are crucial to understand code. However, good names are notoriously hard to choose and manually changing a globally visible name can be a maintenance nightmare. Hence, tool support for automated renaming is an essential aid for developers and widely supported by popular development environments. This work improves on two limitations in current refactoring tools: too weak preconditions that lead to unsoundness where names do not bind to the correct declarations after renaming, and too strong preconditions that prevent renaming of certain programs. We identify two main reasons for unsoundness: complex name lookup rules make it hard to define sufficient preconditions, and new language features require additional preconditions. We alleviate both problems by presenting a novel extensible technique for creating symbolic names that are guaranteed to bind to a desired entity in a particular context by inverting lookup functions. The inverted lookup functions can then be tailored to create qualified names where otherwise a conflict would occur, allowing the refactoring to proceed and improve on the problem with too strong preconditions. We have implemented renaming for Java as an extension to the JastAdd Extensible Java Compiler and integrated it in Eclipse. We show examples for which other refactoring engines have too weak preconditions, as well as examples where our approach succeeds in renaming entities by inserting qualifications. To validate the extensibility of the approach we have implemented renaming support for Java 5 and AspectJ like inter-type declarations as modular extensions to the initial Java 1.4 refactoring engine. The renaming engine is only a few thousand lines of code including extensions and performance is on par with industrial strength refactoring tools.

[1]  Torbjörn Ekman,et al.  The JastAdd Extensible Java Compiler , 2007 .

[2]  Ran Ettinger,et al.  Refactoring via Program Slicing and Sliding , 2007, ICSM.

[3]  Marcio Lopes Cornelio Refactoring as formal refinements , 2004 .

[4]  Torbjörn Ekman,et al.  Modularity first: a case for mixing AOP and attribute grammars , 2008, AOSD.

[5]  Paulo Borba,et al.  Deriving refactorings for AspectJ , 2005, AOSD '05.

[6]  Oege de Moor,et al.  JunGL: a scripting language for refactoring , 2006, ICSE.

[7]  Michael D. Ernst,et al.  Converting java programs to use generic libraries , 2004, OOPSLA '04.

[8]  Don Roberts,et al.  Practical analysis for refactoring , 1999 .

[9]  Tom Mens,et al.  Formalising Behaviour Preserving Program Transformations , 2002, ICGT.

[10]  Guy L. Steele,et al.  Java(TM) Language Specification, The (3rd Edition) (Java (Addison-Wesley)) , 2005 .

[11]  William F. Opdyke,et al.  Refactoring object-oriented frameworks , 1992 .

[12]  Jose Meseguer,et al.  Formal Specification and Verification of Java Refactorings , 2006, 2006 Sixth IEEE International Workshop on Source Code Analysis and Manipulation.

[13]  Guy L. Steele,et al.  The Java Language Specification , 1996 .

[14]  Simon J. Thompson,et al.  Mechanical verification of refactorings , 2008, PEPM '08.

[15]  Torbjörn Ekman,et al.  Development of a Modelica Compiler Using JastAdd , 2008, Electron. Notes Theor. Comput. Sci..

[16]  Torbjörn Ekman,et al.  Modular Name Analysis for Java Using JastAdd , 2005, GTTSE.

[17]  Frank Tip,et al.  Refactoring support for class library migration , 2005, OOPSLA '05.

[18]  Stefan Hanenberg,et al.  Refactoring of Aspect-Oriented Software , 2003 .

[19]  Frank Tip,et al.  Refactoring for generalization using type constraints , 2003, OOPSLA '03.

[20]  Amer Diwan,et al.  Converting Java classes to use generics , 2004, OOPSLA '04.

[21]  Darko Marinov,et al.  Automated testing of refactoring engines , 2007, ESEC-FSE '07.