一句话:提出语言无关的 CodeMapper,通过 diff 分析、代码移动检测与相似度选择,将代码区域映射到另一提交中的对应区域。
软件演化中开发者常需把一个提交中的特定代码区域映射到另一个提交,例如查看 if 条件、配置行或函数定义如何变化,这称为代码映射问题。现有 git diff 只展示文件全部变化,其他技术又局限于特定程序元素和语言。本文提出 CodeMapper,独立于具体程序元素与编程语言。方法分两阶段:先分析 diff、检测代码移动并搜索代码片段以产生候选区域;再计算相似度选择最可能的对应区域。作者在四个数据集上评估,包括两个新构建的、涵盖十种流行语言的手工标注数据集。CodeMapper 在 71.0%–94.5% 的案例中正确识别目标区域,比最佳基线绝对提升 1.5–58.8 个百分点。
During software evolution, developers commonly face the problem of mapping a specific code region from one commit to another. For example, they may want to determine how the condition of an if-statement, a specific line in a configuration file, or the definition of a function changes. We call this the code mapping problem. Existing techniques, such as git diff, address this problem only insufficiently because they show all changes made to a file instead of focusing on a code region of the developer’s choice. Other techniques focus on specific code elements and programming languages (e.g., methods in Java), limiting their applicability. This paper introduces CodeMapper, an approach to address the code mapping problem in a way that is independent of specific program elements and programming languages. Given a code region in one commit, CodeMapper finds the corresponding region in another commit. The approach consists of two phases: (i) computing candidate regions by analyzing diffs, detecting code movements, and searching for specific code fragments, and (ii) selecting the most likely target region by calculating similarities. Our evaluation applies CodeMapper to four datasets, including two new hand-annotated datasets containing code region pairs in ten popular programming languages. CodeMapper correctly identifies the expected target region in 71.0%–94.5% of all cases, improving over the best available baselines by 1.5–58.8 absolute percent points.