一句话:提出 DOME,利用意图引导的选择性注意力,为同一代码生成反映不同开发者意图的注释。
现有自动代码注释生成方法通常只为给定代码片段生成通用的功能描述,未考虑开发者的不同意图;但在真实实践中,注释往往承载功能总结、设计理由、实现细节、代码属性等多种意图。为弥合自动注释生成与真实注释实践之间的差距,本文定义了“开发者意图驱动代码注释生成”任务,即为同一源代码按不同意图生成相应的注释。作者提出 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.