arrow
Return

Recommending Variable Names for Extract Local Variable Refactorings

delete2025-01-13
delete0
PRE
AI
T
Taiming Wang
刘辉 cover
刘辉 (Hui Liu)
Y
Yuxia Zhang
Y
Yanjie Jiang
DOI:10.1145/3712191delete
deleteOriginal
deleteOriginal request for help
deleteShare
deleteSave
Abstract

Abstract

En 中文
<jats:p> <jats:italic>Extract local variable</jats:italic> is one of the most popular refactorings. It is frequently employed to replace occurrences of a complex expression with simple accesses to a newly introduced variable that is initialized by the original complex expression. Consequently, most IDEs and refactoring tools provide automated support for this refactoring, e.g., to suggest names for the newly extracted variables. 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 <jats:italic>VarNamer</jats:italic> , an automated approach designed to recommend variable names for <jats:italic>extract local variable</jats:italic> refactorings. Through a large-scale empirical study, we identify key contexts, such as variable initializations and homogeneous variables (variables whose initializations are identical to that of the newly extracted variable), that are useful for composing variable names. Leveraging these insights, we developed a set of heuristic rules through program static analysis techniques, e.g., lexical analysis, syntax analysis, control flow analysis, and data flow analysis, and employ data mining techniques, i.e., FP-growth algorithm, to recommend variable names effectively. Notably, some of our heuristic rules have been successfully integrated into <jats:italic>Eclipse</jats:italic> , where they are now distributed with the latest releases of the IDE. Evaluation of <jats:italic>VarNamer</jats:italic> on a dataset of 27,158 real-world <jats:italic>extract local variable</jats:italic> refactorings in Java applications demonstrates its superiority over state-of-the-art IDEs. Specifically, <jats:italic>VarNamer</jats:italic> significantly increases the chance of exact match by 52.6% compared to <jats:italic>Eclipse</jats:italic> and 40.7% compared to <jats:italic>IntelliJ IDEA</jats:italic> . 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 <jats:italic>VarNamer</jats:italic> . Finally, we designed and conducted a user study to investigate the impact of <jats:italic>VarNamer</jats:italic> on developers’ productivity. 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. </jats:p>
Keywords:
extract local variable
variable name recommendation
static analysis
data mining
refactoring

Journal

A
ACM Transactions on Software Engineering and Methodology
IF:
6.2
Papers:
1.2K
Citations:
3.4K

Organization

No organization information available