Semantic Patches for Java Program Transformation (Experience Report)

Developing software often requires code changes that are widespread and applied to multiple locations. There are tools for Java that allow developers to specify patterns for program matching and source-to-source transformation. However, to our knowledge, none allows for transforming code based on its control-flow context. We prototype Coccinelle4J, an extension to Coccinelle, which is a program transformation tool designed for widespread changes in C code, in order to work on Java source code. We adapt Coccinelle to be able to apply scripts written in the Semantic Patch Language (SmPL), a language provided by Coccinelle, to Java source files. As a case study, we demonstrate the utility of Coccinelle4J with the task of API migration. We show 6 semantic patches to migrate from deprecated Android API methods on several open source Android projects. We describe how SmPL can be used to express several API migrations and justify several of our design decisions.

[1]  Miryung Kim,et al.  A graph-based approach to API usage adaptation , 2010, OOPSLA.

[2]  Weiyi Shang,et al.  Exploring the Use of Automated API Migrating Techniques in Practice: An Experience Report on Android , 2018, 2018 IEEE/ACM 15th International Conference on Mining Software Repositories (MSR).

[3]  Julia L. Lawall,et al.  Increasing Automation in the Backporting of Linux Drivers Using Coccinelle , 2015, 2015 11th European Dependable Computing Conference (EDCC).

[4]  Thierry Coupaye,et al.  ASM: a code manipulation tool to implement adaptable systems , 2002 .

[5]  D. Chitraprasad,et al.  The varying faces of a program transformation systems , 2012, INROADS.

[6]  Lu Zhang,et al.  A history-based matching approach to identification of framework evolution , 2012, 2012 34th International Conference on Software Engineering (ICSE).

[7]  Günter Kniesel,et al.  JMangler - a framework for load-time transformation of Java class files , 2001, Proceedings First IEEE International Workshop on Source Code Analysis and Manipulation.

[8]  Julia L. Lawall,et al.  Documenting and automating collateral evolutions in linux device drivers , 2008, Eurosys '08.

[9]  Julia L. Lawall,et al.  SmPL: A Domain-Specific Language for Specifying Collateral Evolutions in Linux Device Drivers , 2006, Electron. Notes Theor. Comput. Sci..

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

[11]  Philip Wadler,et al.  Featherweight Java: a minimal core calculus for Java and GJ , 1999, OOPSLA '99.

[12]  Damien Doligez,et al.  A foundation for flow-based program matching: using temporal logic and model checking , 2009, POPL '09.

[13]  David Lo,et al.  Understanding Widespread Changes: A Taxonomic Study , 2013, 2013 17th European Conference on Software Maintenance and Reengineering.

[14]  Renaud Pawlak,et al.  SPOON: A library for implementing analyses and transformations of Java source code , 2016, Softw. Pract. Exp..

[15]  Miryung Kim,et al.  An Empirical Study of API Stability and Adoption in the Android Ecosystem , 2013, 2013 IEEE International Conference on Software Maintenance.

[16]  Julia L. Lawall,et al.  Semantic patches considered helpful , 2006, OPSR.

[17]  Jacques Klein,et al.  Characterising Deprecated Android APIs , 2018, 2018 IEEE/ACM 15th International Conference on Mining Software Repositories (MSR).

[18]  Louis Wasserman Scalable, example-based refactorings with refaster , 2013, WRT '13.

[19]  Eelco Visser,et al.  Stratego: A Language for Program Transformation Based on Rewriting Strategies , 2001, RTA.

[20]  Baojian Hua An Imperative Core Calculus for Java ∗ , 2008 .

[21]  David Notkin,et al.  Using twinning to adapt programs to alternative APIs , 2010, 2010 ACM/IEEE 32nd International Conference on Software Engineering.

[22]  Jun Li,et al.  SWIN: Towards Type-Safe Java Program Adaptation between APIs , 2015, PEPM.

[23]  Martin P. Robillard,et al.  SemDiff: Analysis and recommendation support for API evolution , 2009, 2009 IEEE 31st International Conference on Software Engineering.

[24]  J. Henkel,et al.  CatchUp! Capturing and replaying refactorings to support API evolution , 2005, Proceedings. 27th International Conference on Software Engineering, 2005. ICSE 2005..

[25]  Julia L. Lawall,et al.  Coccinelle: 10 Years of Automated Evolution in the Linux Kernel , 2018, USENIX Annual Technical Conference.

[26]  Laurie Hendren,et al.  Soot: a Java bytecode optimization framework , 2010, CASCON.

[27]  Shigeru Chiba Javassist - A Reflection-based Programming Wizard for Java , 1998 .

[28]  Jun Li,et al.  Transforming Programs between APIs with Many-to-Many Mappings , 2016, ECOOP.