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.
翻译:提取局部变量是最常用的重构操作之一,大多数集成开发环境(IDE)和重构工具都为此重构提供自动化支持。然而,我们发现这些IDE推荐的变量名中约有70%与开发者手动构建的名称不同,这给开发者增加了额外的重命名负担,提供的帮助有限。本文提出VarNamer,一种为提取局部变量重构推荐变量名的自动化方法。通过大规模实证研究,我们识别出对构建变量名有用的关键上下文。基于这些洞见,我们通过程序静态分析技术开发了一套启发式规则,并采用数据挖掘技术来有效推荐变量名。值得注意的是,我们的部分启发式规则已成功集成到Eclipse中,并随该IDE的最新版本发布。评估结果表明,该方法优于当前最先进的IDE。具体而言,与Eclipse相比,VarNamer将精确匹配的概率显著提高了52.6%;与IntelliJ IDEA相比,提高了40.7%。我们还在C++项目中进行的真实提取局部变量重构上评估了所提出的方法,结果表明该方法在Java以外的编程语言上也能达到相当的性能。这可能暗示了VarNamer的普适性。最后,我们设计并实施了用户研究,其结果表明我们的方法可将重构速度提升27.8%,并将推荐变量名的编辑量减少49.3%。