Scripting parametric refactorings in Java to retrofit design patterns

Retrofitting design patterns into a program by hand is tedious and error-prone. A programmer must distinguish refactorings that are provided by an Integrated Development Environment (IDE) from those that must be realized manually, determine a precise sequence of refactorings to apply, and perform this sequence repetitively to a laborious degree. We designed, implemented, and evaluated Reflective Refactoring (R2), a Java package to automate the creation of classical design patterns (Visitor, Abstract Factory, etc.), their inverses, and variants. We encoded 18 out of 23 Gang-of-Four design patterns as R2 scripts and explain why the remaining are inappropriate for refactoring engines. We evaluate the productivity and scalability of R2 with a case study of 6 real-world applications. In one case, R2 automatically created a Visitor with 276 visit methods by invoking 554 Eclipse refactorings in 10 minutes - an achievement that could not be done manually. R2 also sheds light on why refactoring correctness, expressiveness, and speed are critical issues for scripting in next-generation refactoring engines.

[1]  Gabriele Bavota,et al.  On the Impact of Refactoring Operations on Code Quality Metrics , 2014, 2014 IEEE International Conference on Software Maintenance and Evolution.

[2]  Paul Klint,et al.  Using The Meta-Environment for Maintenance and Renovation , 2007, 11th European Conference on Software Maintenance and Reengineering (CSMR'07).

[3]  Andrew P. Black,et al.  How we refactor, and how we know it , 2009, 2009 IEEE 31st International Conference on Software Engineering.

[4]  Jongwook Kim,et al.  Design Pattern Refactoring by Pretty-Printing , 2015 .

[5]  Susan L. Graham,et al.  iXj: interactive source-to-source transformations for java , 2004, OOPSLA '04.

[6]  Arie van Deursen,et al.  The Asf+Sdf Meta-Environment: a Component-Based Language Development Environment , 2001, LDTA@ETAPS.

[7]  Gabriele Bavota,et al.  Methodbook: Recommending Move Method Refactorings via Relational Topic Models , 2014, IEEE Transactions on Software Engineering.

[8]  Ralph Johnson,et al.  design patterns elements of reusable object oriented software , 2019 .

[9]  Siau-Cheng Khoo,et al.  Scalable detection of missed cross-function refactorings , 2014, ISSTA 2014.

[10]  James R. Cordy,et al.  The TXL source transformation language , 2006, Sci. Comput. Program..

[11]  John Brant,et al.  The SmaCC transformation engine: how to convert your entire code base into a different programming language , 2009, OOPSLA Companion.

[12]  Don S. Batory,et al.  Evolving Object-Oriented Designs with Refactorings , 2004, Automated Software Engineering.

[13]  Gabriele Bavota,et al.  Playing with refactoring: Identifying extract class opportunities through game theory , 2010, 2010 IEEE International Conference on Software Maintenance.

[14]  Gabriele Bavota,et al.  Automating extract class refactoring: an improved method and its evaluation , 2013, Empirical Software Engineering.

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

[16]  Ralph E. Johnson,et al.  Automated Detection of Refactorings in Evolving Components , 2006, ECOOP.

[17]  Lori L. Pollock,et al.  How do code refactorings affect energy usage? , 2014, ESEM '14.

[18]  Eelco Visser,et al.  Stratego/XT 0.17. A language and toolset for program transformation , 2008, Sci. Comput. Program..

[19]  Gabriele Bavota,et al.  Identifying Extract Class refactoring opportunities using structural and semantic cohesion measures , 2011, J. Syst. Softw..

[20]  Andrew Begel,et al.  Managing Duplicated Code with Linked Editing , 2004, 2004 IEEE Symposium on Visual Languages - Human Centric Computing.

[21]  Tom Mens,et al.  A declarative evolution framework for object-oriented design patterns , 2001, Proceedings IEEE International Conference on Software Maintenance. ICSM 2001.

[22]  Ralph E. Johnson,et al.  Design Patterns: Abstraction and Reuse of Object-Oriented Design , 1993, ECOOP.

[23]  Jens Dietrich,et al.  On the Existence of High-Impact Refactoring Opportunities in Programs , 2012, ACSC.

[24]  Alejandra Garrido,et al.  Program refactoring in the presence of preprocessor directives , 2005 .

[25]  Emerson R. Murphy-Hill,et al.  Reconciling manual and automatic refactoring , 2012, 2012 34th International Conference on Software Engineering (ICSE).

[26]  Jan Verelst,et al.  Refactoring - improving coupling and cohesion of existing code , 2004, 11th Working Conference on Reverse Engineering.

[27]  Don Batory,et al.  A Tutorial on Feature Oriented Programming and the AHEAD Tool Suite and the AHEAD Tool Suite , 2006 .

[28]  I.D. Baxter,et al.  DMS/spl reg/: program transformations for practical scalable software evolution , 2004, Proceedings. 26th International Conference on Software Engineering.

[29]  Ricardo Terra,et al.  Recommending Move Method refactorings using dependency sets , 2013, 2013 20th Working Conference on Reverse Engineering (WCRE).

[30]  Paul Klint,et al.  Scripting a refactoring with Rascal and Eclipse , 2012, WRT '12.

[31]  Siau-Cheng Khoo,et al.  Vector abstraction and concretization for scalable detection of refactorings , 2014, FSE 2014.

[32]  Arie van Deursen,et al.  The ASF+SDF Meta-environment: A Component-Based Language Development Environment , 2001 .

[33]  Christopher W. Pidgeon,et al.  DMS®: Program Transformations for Practical Scalable Software Evolution , 2002, IWPSE '02.

[34]  Stephan Diehl,et al.  Comparison of similarity metrics for refactoring detection , 2011, MSR '11.

[35]  Stas Negara,et al.  Use, disuse, and misuse of automated refactorings , 2012, 2012 34th International Conference on Software Engineering (ICSE).

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

[37]  Johannes Stammel,et al.  Search-based determination of refactorings for improving the class structure of object-oriented systems , 2006, GECCO.

[38]  Kathryn T. Stolee,et al.  Refactoring pipe-like mashups for end-user programmers , 2011, 2011 33rd International Conference on Software Engineering (ICSE).

[39]  Friedrich Steimann,et al.  A Refactoring Constraint Language and Its Application to Eiffel , 2011, ECOOP.

[40]  Mark Harman,et al.  Experimental assessment of software metrics using automated refactoring , 2012, Proceedings of the 2012 ACM-IEEE International Symposium on Empirical Software Engineering and Measurement.

[41]  Joshua Kerievsky,et al.  Refactoring to Patterns , 2004, XP/Agile Universe.

[42]  Serge Demeyer,et al.  An Initial Investigation into Change-Based Reconstruction of Floss-Refactorings , 2013, 2013 IEEE International Conference on Software Maintenance.

[43]  Huiqing Li,et al.  A Domain-Specific Language for Scripting Refactorings in Erlang , 2012, FASE.

[44]  Gabriele Bavota,et al.  Recommending refactorings based on team co-maintenance patterns , 2014, ASE.

[45]  William G. Griswold Program restructuring as an aid to software maintenance , 1992 .

[46]  Friedrich Steimann,et al.  From Public to Private to Absent: Refactoring Java Programs under Constrained Accessibility , 2009, ECOOP.

[47]  Rob Miller,et al.  Interactive Simultaneous Editing of Multiple Text Regions , 2001, USENIX ATC, General Track.

[48]  Ricardo Terra,et al.  Recommending automated extract method refactorings , 2014, ICPC 2014.

[49]  Krzysztof Czarnecki,et al.  Recommending Refactorings to Reverse Software Architecture Erosion , 2012, 2012 16th European Conference on Software Maintenance and Reengineering.

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

[51]  Pierre-Etienne Moreau,et al.  Tom: Piggybacking Rewriting on Java , 2007, RTA.

[52]  Gabriele Bavota,et al.  Recommending Refactoring Operations in Large Software Systems , 2014, Recommendation Systems in Software Engineering.

[53]  Ewan D. Tempero,et al.  Identifying refactoring opportunities by identifying dependency cycles , 2006, ACSC.

[54]  Alexander Chatzigeorgiou,et al.  Identification of Move Method Refactoring Opportunities , 2009, IEEE Transactions on Software Engineering.

[55]  Oege de Moor,et al.  Specifying and implementing refactorings , 2010, OOPSLA.