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, 这是一种利用源代码中源导选择性注意明确选择与意图有关的信息,并产生反映不同意图的各种评论的方法。我们的方法在两个真实世界爪哇数据集上进行了评价,实验结果显示,我们的方法超过了最新基线。一项人类评价还证实了在实际使用中应用DME的巨大潜力,使开发者能够根据自己的需要有效地评论代码。