An Automated Approach to Extracting Local Variables
Xiaye Chi, Hui Liu, Guangjie Li, Weixiao Wang, Yunni Xia, Yanjie Jiang, Yuxia Zhang, Weixing Ji
Abstract
Extract local variable is a well-known and widely used refactoring. It is frequently employed to replace one or more occurrences of a complex expression with simple accesses to a newly added variable. Although most IDEs provide tool support for extract local variables, such tools without deep analysis of the refactorings may result in semantic errors. To this end, in this paper, we propose a novel and more reliable approach, called ValExtractor, to conduct extract variable refactorings automatically. The major challenge of automated extract local variable refactorings is how to efficiently and accurately identify the side effect of the extracted expressions and the potential interaction between the extracted expressions and their contexts without time-consuming dynamic execution of the involved programs. To resolve this challenge, ValExtractor leverages a lightweight static source code analysis to validate the side effect of the selected expression, and to identify which occurrences of the selected expression could be extracted together without changing the semantics of the program or introducing potential new exceptions. Our evaluation results on open-source Java applications suggest that Eclipse and IntelliJ IDEA, the state-of-the-practice refactoring engines, resulted in a large number of faulty extract variable refactorings whereas ValExtractor successfully avoided all such errors. The proposed approach has been merged into (and distributed with) Eclipse to improve the safety of extract local variable refactoring.
Ask about this paper
Ask your agent about it.
Lune has read the top-tier papers around this one, so every answer names the papers it rests on.
Your agent calls
Lunesearch_papers
Free to start. No credit card required.
Terminal
Install the CLIlune papers get ed1e1652-cb42-4a33-8ebc-1ca0c2d34187Cited by top-tier papers1
Ask how each one uses itRelated papers
- The untold story of code refactoring customizations in practiceDaniel Oliveira, Wesley K. G. Assunção, Alessandro F. Garcia, Ana Carla Bibiano et al.ICSE 2023 · 11 citations
- Adventure of a Lifetime: Extract Method Refactoring for RustSewen Thy, Andreea Costea, Kiran Gopinathan, Ilya SergeyOOPSLA 2023 · 6 citations
- Cross-Refactoring-Type Test Program Migration for Refactoring EnginesChunhao Dong, Yanjie Jiang, Yang Zhang, Yuxia Zhang et al.FSE 2026
- Chatgpt-Based Test Generation for Refactoring Engines Enhanced by Feature Analysis on ExamplesChunhao Dong, Yanjie Jiang, Yuxia Zhang, Yang Zhang et al.ICSE 2025 · 4 citations
- Automated Unit Test RefactoringYi Gao, Xing Hu, Xiaohu Yang, Xin XiaFSE 2025 · 6 citations
