一句话:提出 GTNM,融合局部上下文、项目特定上下文和文档,显著提升方法名推荐效果。
在程序理解中,方法名应具有意义并与代码库中相关命名保持一致。现有基于神经机器翻译的方法名推荐模型主要从方法体或邻近方法中抽取代码特征,忽略了目标方法的项目特定上下文和文档信息。本文首先通过统计方法分析方法名与其上下文之间的关系,并据此提出 GTNM:一种基于 Transformer 的全局神经模型,同时考虑局部上下文、项目特定上下文以及目标方法的文档。在 Java 方法上的实验表明,GTNM 在方法名推荐任务上大幅超越当前最佳结果,验证了所提模型的有效性。
In programming, the names for the program entities, especially for the methods, are the intuitive characteristic for understanding the functionality of the code. To ensure the readability and maintainability of the programs, method names should be named properly. Specifically, the names should be meaningful and consistent with other names used in related contexts in their codebase. In recent years, many automated approaches are proposed to suggest consistent names for methods, among which neural machine translation (NMT) based models are widely used and have achieved state-of-the-art results. However, these NMT-based models mainly focus on extracting the code-specific features from the method body or the surrounding methods, the project-specific context and documentation of the target method are ignored. We conduct a statistical analysis to explore the relationship between the method names and their contexts. Based on the statistical results, we propose GTNM, a Global Transformer-based Neural Model for method name suggestion, which considers the local context, the project-specific context, and the documentation of the method simultaneously. Experimental results on java methods show that our model can outperform the state-of-the-art results by a large margin on method name suggestion, demonstrating the effectiveness of our proposed model.
DOI 原文 ·
@inproceedings{paperbot6955,
title = {Learning to recommend method names with global context},
author = {Fang Liu and Ge Li and Zhiyi Fu and Shuai Lu and Yiyang Hao and Zhi Jin},
booktitle = {ICSE},
year = {2022},
doi = {10.1145/3510003.3510154}
}