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.
翻译:现有自动代码注释生成方法主要侧重于为给定代码片段生成通用功能描述,而未考虑开发者的意图。然而在实际开发中,注释内容往往较为复杂,常包含反映开发者多种意图的信息,例如功能总结、设计原理、实现细节、代码属性等。为弥合自动代码注释生成与真实注释实践之间的差距,我们定义了开发者意图驱动的代码注释生成任务,该任务能够针对同一源代码生成具有不同意图感知的注释。为应对这一挑战性任务,我们提出DOME方法,该方法采用意图引导的选择性注意力机制,从源代码中显式选择与意图相关的信息,并生成反映不同意图的多样化注释。我们在两个真实Java数据集上进行了评估,实验结果表明该方法优于现有最优基线模型。人工评估也证实了DOME在实际应用中的显著潜力,能够使开发者根据自身需求高效地注释代码。