Automating the development of API-based generators using code idioms mining
摘要
API-Based Generators (ABGs) allow practitioners to achieve the advantages of Model-Driven Engineering (MDE) without making significant changes to their current workflow or the architecture of their solution. However, using ABGs that are defined in terms of the syntax rules of a target language can be cumbersome and impractical. Additionally, manually developing an ABG based on higher-level concepts already used in an existing solution is labor-intensive and time-consuming. This paper introduces a new approach called Semi-automatic API-based Generators Development (SAGED) to expedite the creation of ABGs customized for MDE development of existing solutions. SAGED accomplishes this by (i) providing insight into code idioms that could be considered good candidates for code generation, as they frequently appear in the codebase, and (ii) automating the creation of a code generation API for an ABG, defined in terms of the identified code idioms. The SAGED approach relies on mining code idioms from existing, unlabeled source code based on a machine learning technique called the nonparametric Bayesian Probabilistic Tree Substitution Grammar (PTSG). The main contributions of this paper include the introduction of the SAGED approach, an explanation and optimization of the Type-Based MCMC as a method for approximating the nonparametric Bayesian PTSG, and the development of an open-source inference core for implementing the inference method in different programming languages. Furthermore, the paper presents a solution for implementing SAGED in the C# programming language, along with case studies that demonstrate its effectiveness.