Software developers often struggle to update APIs, leading to manual, time-consuming, and error-prone processes. We introduce MELT, a new approach that generates lightweight API migration rules directly from pull requests in popular library repositories. Our key insight is that pull requests merged into open-source libraries are a rich source of information sufficient to mine API migration rules. By leveraging code examples mined from the library source and automatically generated code examples based on the pull requests, we infer transformation rules in \comby, a language for structural code search and replace. Since inferred rules from single code examples may be too specific, we propose a generalization procedure to make the rules more applicable to client projects. MELT rules are syntax-driven, interpretable, and easily adaptable. Moreover, unlike previous work, our approach enables rule inference to seamlessly integrate into the library workflow, removing the need to wait for client code migrations. We evaluated MELT on pull requests from four popular libraries, successfully mining 461 migration rules from code examples in pull requests and 114 rules from auto-generated code examples. Our generalization procedure increases the number of matches for mined rules by 9x. We applied these rules to client projects and ran their tests, which led to an overall decrease in the number of warnings and fixing some test cases demonstrating MELT's effectiveness in real-world scenarios.
翻译:软件开发者在更新API时常常面临困难,导致手动操作过程耗时且易出错。本文介绍MELT——一种直接从流行库仓库的拉取请求中生成轻量级API迁移规则的新方法。我们的核心洞见是:合并到开源库中的拉取请求蕴含着足以挖掘API迁移规则的丰富信息源。通过利用从库源码挖掘的代码示例以及基于拉取请求自动生成的代码示例,我们推导出\comby(一种用于结构化代码搜索替换的语言)中的转换规则。由于从单个代码示例推导的规则可能过于特定,我们提出了一种泛化流程以提升规则在客户端项目中的适用性。MELT规则具有语法驱动、可解释和易适配的特点。此外,与先前工作不同,我们的方法使规则推导能够无缝集成到库工作流中,无需等待客户端代码迁移。我们在四个流行库的拉取请求上评估MELT,成功从拉取请求的代码示例中挖掘出461条迁移规则,并通过自动生成代码示例获得114条规则。泛化流程使挖掘规则的匹配数量提升9倍。我们将这些规则应用于客户端项目并运行测试,结果显示警告总数整体减少,部分测试用例得到修复,这证明了MELT在实际场景中的有效性。