一句话:提出 CUP,利用神经序列到序列模型从代码-注释协同变更中学习,自动生成与新代码一致的注释。
代码注释对程序理解与维护至关重要,但开发者修改代码时常忽略同步更新注释,产生不一致或过时注释(bad comments),可能误导开发者并诱发缺陷。本文提出“即时注释更新”(JIT Comment Updating)任务与工具 CUP,基于旧注释和代码变更自动生成新注释。CUP 采用神经序列到序列模型,从历史代码-注释协同变更中学习更新模式,并引入专用分词器与协同注意力等定制增强。作者构建了包含逾 10.8 万条注释-代码协同变更样本的数据集。实验表明,CUP 显著优于基于信息检索和规则的基线,并减少开发者编辑量;在 1612(16.7%)个测试样本中生成注释与开发者更新完全一致,是最佳基线的 7 倍。
Code comments are valuable for program comprehension and software maintenance, and also require maintenance with code evolution. However, when changing code, developers sometimes neglect updating the related comments, bringing in inconsistent or obsolete comments (aka., bad comments). Such comments are detrimental since they may mislead developers and lead to future bugs. Therefore, it is necessary to fix and avoid bad comments. In this work, we argue that bad comments can be reduced and even avoided by automatically performing comment updates with code changes. We refer to this task as "Just-In-Time (JIT) Comment Updating" and propose an approach named CUP (Comment UPdater) to automate this task. CUP can be used to assist developers in updating comments during code changes and can consequently help avoid the introduction of bad comments. Specifically, CUP leverages a novel neural sequence-to-sequence model to learn comment update patterns from extant code-comment co-changes and can automatically generate a new comment based on its corresponding old comment and code change. Several customized enhancements, such as a special tokenizer and a novel co-attention mechanism, are introduced in CUP by us to handle the characteristics of this task. We build a dataset with over 108K comment-code co-change samples and evaluate CUP on it. The evaluation results show that CUP outperforms an information-retrieval-based and a rule-based baselines by substantial margins, and can reduce developers' edits required for JIT comment updating. In addition, the comments generated by our approach are identical to those updated by developers in 1612 (16.7%) test samples, 7 times more than the best-performing baseline.
DOI 原文 ·
@inproceedings{paperbot5942,
title = {Automating just-in-time comment updating},
author = {Zhongxin Liu and Xin Xia and Meng Yan and Shanping Li},
booktitle = {ASE},
year = {2020},
doi = {10.1145/3324884.3416581}
}