跳到主要导航 跳到搜索 跳到主要内容

Automated Recommendation of Extracting Local Variable Refactorings

  • Yanjie Jiang
  • , Xiaye Chi
  • , Yuxia Zhang
  • , Weixing Ji
  • , Guangjie Li
  • , Weixiao Wang
  • , Yunni Xia
  • , Lu Zhang
  • , Hui Liu*
  • *此作品的通讯作者
  • Peking University
  • Beijing Institute of Technology
  • National Innovation Institute of Defense Technology
  • Chongqing University

科研成果: 期刊稿件 › 文章 › 同行评审

摘要

Extracting local variable refactoring is frequently employed to replace one or more occurrences of a complex expression with simple accesses to a newly introduced variable. To facilitate refactoring, most IDEs can automate the extract local variable refactorings when the to-be-extracted expressions are selected by developers. However, refactoring tools usually replace all expressions that are lexically identical to the selected one without a comprehensive analysis of the safety of the refactoring. The automatically conducted refactorings may lead to serious software defects. Besides that, existing refactoring tools rely heavily on software developers to spot to-be-extracted expressions although it is often challenging for inexperienced developers and maintainers to make the selection. To this end, in this article, we propose an automated approach, called ValExtractor+, to recommending extract local variable refactoring opportunities and to automatically and safely conduct the refactorings. ValExtractor+ is composed of two parts, i.e., solutionAdvisor and opportunityAdvisor. Given a to-be-extracted expression, solutionAdvisor leverages lightweight static source code analysis to validate potential side effects of the expression, and to identify expressions that could be extracted together with the selected expression as a single variable without changing the semantics of the program or introducing any new exceptions. The static code analysis significantly improves the safety of automated extraction of local variables. To free programmers from manually selecting to-be-extracted expressions, opportunityAdvisor leverages solutionAdvisor to automatically retrieve all expressions that could be extracted safely as well as their refactoring solutions. It then leverages a learning-based classifier to predict which of the retrieved expressions should be extracted. Evaluations on open-source applications suggest that solutionAdvisor successfully avoided all defects (more than two hundred) caused by extracting local variable refactorings conducted by Eclipse (243 defects) or IntelliJ IDEA (263 defects). Additionally, opportunityAdvisor was able to effectively recommend expressions for extraction, achieving 307 true positives (TP) and 21,121 true negatives (TN). Four pull requests from our work (PR IDs: 66, 333, 439, and 360) were successfully merged into the Eclipse community repository, showcasing the practical impact and robustness of our approach as recognized by the wider developer community.

源语言英语
期刊论文编号230
期刊ACM Transactions on Software Engineering and Methodology
卷34
期8
DOI
出版状态已出版 - 6 10月 2025

学术指纹

探究 'Automated Recommendation of Extracting Local Variable Refactorings' 的科研主题。它们共同构成独一无二的学术指纹。

引用此