paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Lightweight global and local contexts guided method name recommendation with prior knowledge

融合先验知识的轻量级全局与局部上下文引导方法名推荐
FSE Proceedings of the 29th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering2021匹配度 3/10 · 该论文研究基于程序上下文的方法名推荐,属于软件工程/开发者工具方向,与静态分析有间接关联;但未涉及LLM/Agent、浮点程序分析、贝叶斯程序分析或形式化验证等用户核心方向,也不是用LLM改进静态分析或为Agentic程序做分析。引用 37 inbox
Shangwen Wang, Ming Wen, Bo Lin, Xiaoguang Mao
crossref: 2026-09-12

AI 速览

一句话:提出Cognac,融合局部/全局上下文与先验知识,提升方法名推荐及一致性检查效果。

方法名质量影响代码可读性与可维护性,但构造简洁名称常具挑战。现有推荐方法的瓶颈是仅利用目标方法自身信息,且未区分不同程序上下文 token 的贡献。基于14K+项目、12M+方法的实证分析,作者发现方法名 token 常出现在其调用者/被调用者中,且不同上下文 token 的贡献概率不同。据此提出 Cognac:同时利用目标方法的局部上下文与有调用关系的全局上下文,并以实证结果作为先验知识指导名称生成、限制全局 token 数量。在四个数据集上,F-score 分别为63.2%、60.8%、66.3%、68.5%,均优于现有方法;一致性检查准确率达76.6%,超 MNire 11.2%。消融表明 caller/callee 信息与先验知识贡献显著。

问题
现有方法名推荐方法的瓶颈在于信息局限于目标方法自身,且未区分不同程序上下文提取 token 的贡献。
方法
通过大规模实证分析发现调用者/被调用者中包含有用名称 token,并提出 Cognac,结合局部与全局上下文,并用先验知识指导名称生成及限制全局 token 数量。
评估
在四个常用数据集上比较 F-score,并在方法名一致性检查任务上比较总体准确率,同时通过消融验证 caller/callee 信息与先验知识的作用。
原文摘要(Abstract)

The quality of method names is critical for the readability and maintainability of source code. However, it is often challenging to construct concise method names. To alleviate this problem, a number of approaches have been proposed to automatically recommend high-quality names for methods. Despite being effective, existing approaches meet their bottlenecks mainly in two aspects: (1) the leveraged information is restricted to the target method itself; and (2) lack of distinctions towards the contributions of tokens extracted from different program contexts. Through a large-scale empirical analysis on +12M methods from +14K real-world projects, we found that (1) the tokens composing a method’s name can be frequently observed in its callers/callees; and (2) tokens extracted from different specific contexts have diverse probabilities to compose the target method’s name. Motivated by our findings, we propose, in this paper, a context-guided method name recommender, which mainly embodies two key ideas: (1) apart from the local context, which is extracted from the target method itself, we also consider the global context, which is extracted from other methods in the project that have call relations with the target method, to include more useful information; and (2) we utilize our empirical results as the prior knowledge to guide the generation of method names and also to restrict the number of tokens extracted from the global contexts. We implemented the idea as Cognac and performed extensive experiments to assess its effectiveness. Results reveal that can (1) perform better than existing approaches on the method name recommendation task (e.g., it achieves an F-score of 63.2%, 60.8%, 66.3%, and 68.5%, respectively, on four widely-used datasets, which all outperform existing techniques); and (2) achieve higher performance than existing techniques on the method name consistency checking task (e.g., its overall accuracy reaches 76.6%, outperforming the state-of-the-art MNire by 11.2%). Further results reveal that the caller/callee information and the prior knowledge all contribute significantly to the overall performance of Cognac.

链接与引用

DOI 原文 ·

BibTeX
@inproceedings{paperbot6405,
  title = {Lightweight global and local contexts guided method name recommendation with prior knowledge},
  author = {Shangwen Wang and Ming Wen and Bo Lin and Xiaoguang Mao},
  booktitle = {FSE},
  year = {2021},
  doi = {10.1145/3468264.3468567}
}