一句话:提出迭代式基于相似度的 AST 映射算法 iASTMapper,通过三层节点迭代与相互影响机制提升代码变更定位准确率。
现有 AST 映射算法(如 GumTree、MTDiff、IJM)在大量文件修订中会产生不准确的节点映射,其关键原因之一是低层节点(如 token)与高层节点(如语句)的映射之间存在相互影响,而该问题较少被现有方法考虑。为此,本文提出 iASTMapper:从代码修订前后的 AST 中提取 token、statement、inner-statement 三类不同层次节点,先建立未变语句和内语句的映射,再基于启发式相似度迭代映射剩余节点;同时用迭代机制连接三个映射过程,以利用不同层次节点映射间的相互影响,最终从节点映射生成代码编辑动作以帮助理解和定位变更。作者在十个 Java 项目的 210,997 个文件修订上与 GumTree、MTDiff、IJM 自动对比,并邀请 12 名评估者对 200 个修订的编辑动作进行人工评估。结果表明 iASTMapper 优于基线,生成的代码编辑动作至少短 1.29%,准确率达到 96.23%。
Abstract syntax tree (AST) mapping algorithms are widely used to locate the code changes in a file revision by mapping the AST nodes of the source code before and after the code changes. A recent differential testing of three state-of- the-art AST mapping algorithms, i.e., GumTree, MTDiff, and IJM, reveals that the algorithms generate inaccurate mappings for a considerable number of file revisions. We find that the inaccurate mappings could be caused by the mutual influence: the mappings of lower-level AST nodes (e.g., tokens) have impacts on the mappings of higher-level AST nodes (e.g., statements) and vice versa. This mutual influence issue is rarely considered by existing algorithms. In this paper, we propose an algorithm, called iASTMapper, that iteratively map two ASTs based on the similarities between AST nodes. Given a file revision, we extract three types of AST nodes in different levels of program structures (i.e., tokens, statements, and inner-statements) from the ASTs of the two source code files. We first build mappings of the unchanged statements and inner-statements. Then, we use an iterative method to map the rest of the nodes without mapping. For each of the three types of nodes, we iteratively map the nodes based on their similarities measured using heuristic rules. We further use an iterative mechanism to connect the three iterative mapping processes by considering the mutual influence between the mappings of different types of nodes. Finally, a series of code edit actions are generated from the node mappings to help users understand and locate the code changes during revisions. We conduct experiments to compare iASTMapper with three baselines, i.e., GumTree, MTDiff, and IJM, by automatically evaluating 210,997 file revisions from ten Java projects. Furthermore, we manually evaluate the correctness of the code edit actions generated for 200 file revisions with 12 evaluators. The results demonstrate that iASTMapper outperforms the baselines. iASTMapper can generate shorter code edit actions by at least 1.29% than the baselines, with a high accuracy of 96.23%.