Automatic Inference of Java-to-Swift Translation Rules for Porting Mobile Applications

A native cross-platform mobile app has multiple platform-specific implementations. Typically, an app is developed for one platform and then ported to the remaining ones. Translating an app from one language (e.g., Java) to another (e.g., Swift) by hand is tedious and error-prone, while automated translators either require manually defined translation rules or focus on translating APIs. To automate the translation of native cross-platform apps, we present j2sInferer, a novel approach that iteratively infers syntactic transformation rules and API mappings from Java to Swift. Given a software corpus in both languages, j2sInferer first identifies the syntactically equivalent code based on braces and string similarity. For each pair of similar code segments, j2sInferer then creates syntax trees of both languages, leveraging the minimalist domain knowledge of language correspondence (e.g., operators and markers) to iteratively align syntax tree nodes, and to infer both syntax and API mapping rules. j2sInferer represents inferred rules as string templates, stored in a database, to translate code from Java to Swift. We evaluated j2sInferer with four applications, using one part of the data to infer translation rules, and the other part to apply the rules. With 76% in-project accuracy and 65% cross-project accuracy, j2sInferer outperforms in accuracy j2swift, a state-of-the-art Java-to-Swift conversion tool. As native cross-platform mobile apps grow in popularity, j2sInferer can shorten their time to market by automating the tedious and error prone task of source-to-source translation.

[1]  Harry M. Sneed,et al.  Migrating from COBOL to Java , 2010, 2010 IEEE International Conference on Software Maintenance.

[2]  Eli Tilevich,et al.  Cloud Twin: Native execution of android applications on the Windows Phone , 2013, 2013 28th IEEE/ACM International Conference on Automated Software Engineering (ASE).

[3]  Miryung Kim,et al.  Does Automated Refactoring Obviate Systematic Editing? , 2015, 2015 IEEE/ACM 37th IEEE International Conference on Software Engineering.

[4]  Hoan Anh Nguyen,et al.  Graph-based mining of multiple object usage patterns , 2009, ESEC/FSE '09.

[5]  Eli Tilevich,et al.  Native-2-native: automated cross-platform code synthesis from web-based programming resources , 2015, GPCE.

[6]  Eli Tilevich,et al.  Reverse-engineering user interfaces to facilitateporting to and across mobile devices and platforms , 2011, SPLASH Workshops.

[7]  Richard C. Holt,et al.  A lightweight approach for migrating web frameworks , 2005, Inf. Softw. Technol..

[8]  Sumit Gulwani,et al.  Learning Syntactic Program Transformations from Examples , 2016, 2017 IEEE/ACM 39th International Conference on Software Engineering (ICSE).

[9]  Norihisa Doi,et al.  SPiCE: A System for Translating Smalltalk Programs Into a C Environment , 1995, IEEE Trans. Software Eng..

[10]  Anh Tuan Nguyen,et al.  Statistical learning approach for mining API usage mappings for code migration , 2014, ASE.

[11]  Alla Rozovskaya,et al.  Facilitating the development of cross-platform software via automated code synthesis from web-based programming resources , 2017, Comput. Lang. Syst. Struct..

[12]  Maxim Mossienko Automated Cobol to Java recycling , 2003, Seventh European Conference onSoftware Maintenance and Reengineering, 2003. Proceedings..

[13]  Steven S. Muchnick,et al.  Advanced Compiler Design and Implementation , 1997 .

[14]  Amey Karkare,et al.  A feasibility study of using automated program repair for introductory programming assignments , 2017, ESEC/SIGSOFT FSE.

[15]  Qing Wang,et al.  Mining API mapping for language migration , 2010, 2010 ACM/IEEE 32nd International Conference on Software Engineering.

[16]  Mohammad El-Ramly,et al.  An Experiment in Automatic Conversion of Legacy Java Programs to C# , 2006, IEEE International Conference on Computer Systems and Applications, 2006..

[17]  Anh Tuan Nguyen,et al.  Divide-and-Conquer Approach for Multi-phase Statistical Migration for Source Code (T) , 2015, 2015 30th IEEE/ACM International Conference on Automated Software Engineering (ASE).

[18]  Miryung Kim,et al.  Sydit: creating and applying a program transformation from an example , 2011, ESEC/FSE '11.

[19]  Miryung Kim,et al.  Systematic editing: generating program transformations from an example , 2011, PLDI '11.

[20]  Miryung Kim,et al.  Lase: Locating and applying systematic edits by learning from examples , 2013, 2013 35th International Conference on Software Engineering (ICSE).

[21]  Fan Long,et al.  Automatic inference of code transforms for patch generation , 2017, ESEC/SIGSOFT FSE.