arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2507.00413cs.SE
收藏

为提取局部变量重构推荐变量名

Recommending Variable Names for Extract Local Variable Refactorings

Taiming Wang, Hui Liu, Yuxia Zhang, Yanjie Jiang

AI总结:

针对IDE推荐变量名与开发者手动命名差异大的问题,提出VarNamer方法,结合静态分析和数据挖掘推荐变量名,显著提升匹配率并加快重构速度。

摘要:

提取局部变量是最流行的重构之一,大多数IDE和重构工具都为这种重构提供了自动化支持。然而,我们发现这些IDE推荐的名称中约有70%与开发者手动构建的名称不同,这给开发者增加了额外的重命名负担,提供的帮助有限。在本文中,我们介绍了VarNamer,这是一种旨在为提取局部变量重构推荐变量名的自动化方法。通过大规模的实证研究,我们确定了有助于组合变量名的关键上下文。利用这些见解,我们通过程序静态分析技术开发了一组启发式规则,并采用数据挖掘技术来有效地推荐变量名。值得注意的是,我们的一些启发式规则已成功集成到Eclipse中,现在随该IDE的最新版本一起发布。评估表明,它优于最先进的IDE。具体而言,与Eclipse相比,VarNamer将完全匹配的几率显著提高了52.6%,与IntelliJ IDEA相比提高了40.7%。我们还使用在C++项目中进行的真实世界提取局部变量重构评估了所提出的方法,结果表明该方法在Java以外的编程语言上也能实现相当的性能。这可能表明VarNamer具有泛化能力。最后,我们设计并实施了一项用户研究,用户研究的结果表明,我们的方法可以将重构速度提高27.8%,并减少对推荐变量名49.3%的编辑。

英文摘要:

Extract local variable is one of the most popular refactorings, and most IDEs and refactoring tools provide automated support for this refactoring. However, we find approximately 70% of the names recommended by these IDEs are different from what developers manually constructed, adding additional renaming burdens to developers and providing limited assistance. In this paper, we introduce VarNamer, an automated approach designed to recommend variable names for extract local variable refactorings. Through a large-scale empirical study, we identify key contexts that are useful for composing variable names. Leveraging these insights, we developed a set of heuristic rules through program static analysis techniques and employ data mining techniques to recommend variable names effectively. Notably, some of our heuristic rules have been successfully integrated into Eclipse, where they are now distributed with the latest releases of the IDE. Evaluation demonstrates its superiority over state-of-the-art IDEs. Specifically, VarNamer significantly increases the chance of exact match by 52.6% compared to Eclipse and 40.7% compared to IntelliJ IDEA. We also evaluated the proposed approach with real-world extract local variable refactorings conducted in C++ projects, and the results suggest that the approach can achieve comparable performance on programming languages besides Java. It may suggest the generalizability of VarNamer. Finally, we designed and conducted a user study and the results of the user study suggest that our approach can speed up the refactoring by 27.8% and reduce 49.3% edits on the recommended variable names.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑