arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2302.07055cs.SE
收藏

意图驱动的代码注释生成

Developer-Intent Driven Code Comment Generation

Fangwen Mu, Xiao Chen, Lin Shi, Song Wang, Qing Wang

摘要:

现有的自动代码注释生成器主要集中于为给定的代码片段生成功能的一般描述,而不考虑开发者的意图。然而,在现实世界的实践中,注释是复杂的,其通常包含反映开发者的各种意图的信息,例如,功能总结、设计原理、实现细节、代码属性等。为了弥合自动代码注释生成和实际注释实践之间的差距,我们定义了基于意图驱动的代码注释生成,它可以为具有不同意图的相同源代码生成意图感知注释。为了解决这个具有挑战性的任务,我们提出了DOME,一种利用意图引导的选择性注意力来明确地从源代码中选择意图相关信息的方法,并产生反映不同意图的各种评论。我们的方法在两个真实的Java数据集上进行了评估,实验结果表明,我们的方法优于最先进的基线。人工评估也证实了在实际使用中应用DOME的巨大潜力,使开发人员能够根据自己的需求有效地注释代码。

英文摘要:

Existing automatic code comment generators mainly focus on producing a general description of functionality for a given code snippet without considering developer intentions. However, in real-world practice, comments are complicated, which often contain information reflecting various intentions of developers, e.g., functionality summarization, design rationale, implementation details, code properties, etc. To bridge the gap between automatic code comment generation and real-world comment practice, we define Developer-Intent Driven Code Comment Generation, which can generate intent-aware comments for the same source code with different intents. To tackle this challenging task, we propose DOME, an approach that utilizes Intent-guided Selective Attention to explicitly select intent-relevant information from the source code, and produces various comments reflecting different intents. Our approach is evaluated on two real-world Java datasets, and the experimental results show that our approach outperforms the state-of-the-art baselines. A human evaluation also confirms the significant potential of applying DOME in practical usage, enabling developers to comment code effectively according to their own needs.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑