skip to main content
10.1145/3611643.3616261acmconferencesArticle/Chapter ViewAbstractPublication PagesfseConference Proceedingsconference-collections
research-article

An Automated Approach to Extracting Local Variables

Published: 30 November 2023 Publication History

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.

Supplementary Material

Video (fse23main-p169-p-video.mp4)
"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 emph{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."

References

[1]
Robert S Arnold. 1986. An introduction to software restructuring. Tutorial on Software Restructuring, 1–11.
[2]
Block (Eclipse JDT API Specification). 2023. https://help.eclipse.org/topic/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/dom/Block.html
[3]
Brett Daniel, Danny Dig, Kely Garcia, and Darko Marinov. 2007. Automated testing of refactoring engines. In Proceedings of the the 6th joint meeting of the European software engineering conference and the ACM SIGSOFT symposium on The foundations of software engineering (ESEC/FSE). 185–194. https://doi.org/10.1145/1287624.1287651
[4]
Maartje De Jonge and Eelco Visser. 2012. A language generic solution for name binding preservation in refactorings. In Proceedings of the Twelfth Workshop on Language Descriptions, Tools, and Applications (LDTA). 1–8. https://doi.org/10.1145/2427048.2427050
[5]
Defects4J – version 1.1.0. 2023. https://github.com/rjust/defects4j/tree/v1.1.0
[6]
B. Du Bois, S. Demeyer, and J. Verelst. 2004. Refactoring - improving coupling and cohesion of existing code. In 11th Working Conference on Reverse Engineering (WCRE). 144–151. https://doi.org/10.1109/WCRE.2004.33
[7]
Eclipse. 2023. http://www.eclipse.org/
[8]
Eclipse Java development tools (JDT). 2023. https://www.eclipse.org/jdt/
[9]
Anna Maria Eilertsen, Anya Helene Bagge, and Volker Stolz. 2016. Safer refactorings. In International Symposium on Leveraging Applications of Formal Methods (ISoLA). 517–531. https://doi.org/978-3-319-47166-2_36
[10]
Extract/Introduce variable. 2023. https://www.jetbrains.com/help/idea/extract-variable.html
[11]
Martin Fowler. 2018. Refactoring. Addison Wesley.
[12]
Full List of Preconditions. 2023. https://github.com/liuhuigmail/ValExtractor/#Preconditions
[13]
Keheliya Gallaba, Quinn Hanam, Ali Mesbah, and Ivan Beschastnikh. 2017. Refactoring Asynchrony in JavaScript. In 2017 IEEE International Conference on Software Maintenance and Evolution (ICSME). 353–363. https://doi.org/10.1109/ICSME.2017.83
[14]
Milos Gligoric, Farnaz Behrang, Yilong Li, Jeffrey Overbey, Munawar Hafiz, and Darko Marinov. 2013. Systematic testing of refactoring engines on real software projects. In ECOOP 2013 - Object-Oriented Programming - 27th European Conference, Montpellier, France, July 1-5, 2013. Proceedings (Lecture Notes in Computer Science, Vol. 7920). Springer, 629–653. https://doi.org/10.1007/978-3-642-39038-8_26
[15]
Yaroslav Golubev, Zarina Kurbatova, Eman Abdullah AlOmar, Timofey Bryksin, and Mohamed Wiem Mkaouer. 2021. One Thousand and One Stories: A Large-Scale Survey of Software Refactoring. In Proceedings of the 29th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering (ESEC/FSE 2021). Association for Computing Machinery, New York, NY, USA. 1303–1313. isbn:9781450385626 https://doi.org/10.1145/3468264.3473924
[16]
IntelliJ IDEA. 2023. http://www.jetbrains.com/idea/
[17]
ITypeBinding (Eclipse JDT API Specification). 2023. https://help.eclipse.org/topic/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/dom/ITypeBinding.html
[18]
Yanjie Jiang, Hui Liu, Xiaoqing Luo, Zhihao Zhu, Xiaye Chi, Nan Niu, Yuxia Zhang, Yamin Hu, Pan Bian, and Lu Zhang. 2023. BugBuilder: An Automated Approach to Building Bug Repository. IEEE Transactions on Software Engineering, 1–1. https://doi.org/10.1109/TSE.2022.3177713
[19]
Raffi Khatchadourian, Yiming Tang, Mehdi Bagherzadeh, and Syed Ahmed. 2019. Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams. In 2019 IEEE/ACM 41st International Conference on Software Engineering (ICSE). 619–630. https://doi.org/10.1109/ICSE.2019.00072
[20]
Miryung Kim, Thomas Zimmermann, and Nachiappan Nagappan. 2014. An Empirical Study of Refactoring Challenges and Benefits at Microsoft. IEEE Transactions on Software Engineering, 40, 7 (2014), 633–649. https://doi.org/10.1109/TSE.2014.2318734
[21]
Raula Gaikovina Kula, Ali Ouni, Daniel M German, and Katsuro Inoue. 2018. An empirical study on the impact of refactoring activities on evolving client-used APIs. Information and Software Technology, 93 (2018), 186–199. https://doi.org/10.1016/j.infsof.2017.09.007
[22]
Yu Lin, Semih Okur, and Danny Dig. 2015. Study and refactoring of Android asynchronous programming (t). In 2015 30th IEEE/ACM International Conference on Automated Software Engineering (ASE). 224–235. https://doi.org/10.1109/ASE.2015.50
[23]
Melina Mongiovi, Rohit Gheyi, Gustavo Soares, Márcio Ribeiro, Paulo Borba, and Leopoldo Teixeira. 2017. Detecting overly strong preconditions in refactoring engines. IEEE Transactions on Software Engineering, 44, 5 (2017), 429–452. https://doi.org/10.1109/TSE.2017.2693982
[24]
Melina Mongiovi, Rohit Gheyi, Gustavo Soares, Leopoldo Teixeira, and Paulo Borba. 2014. Making refactoring safer through impact analysis. Science of Computer Programming, 93 (2014), 39–64. https://doi.org/10.1016/j.scico.2013.11.001
[25]
Emerson Murphy-Hill, Chris Parnin, and Andrew P Black. 2011. How we refactor, and how we know it. IEEE Transactions on Software Engineering, 38, 1 (2011), 5–18. https://doi.org/10.1109/TSE.2011.41
[26]
Stas Negara, Nicholas Chen, Mohsen Vakilian, Ralph E Johnson, and Danny Dig. 2013. A comparative study of manual and automated refactorings. In ECOOP 2013–Object-Oriented Programming: 27th European Conference, Montpellier, France, July 1-5, 2013. Proceedings 27. 552–576. https://doi.org/10.1007/978-3-642-39038-8_23
[27]
NetBeans. 2023. http://netbeans.org/
[28]
Online Safe Effect Example and Explanation. 2023. https://github.com/liuhuigmail/ValExtractor/blob/main/Example.md
[29]
William F Opdyke. 1992. Refactoring object-oriented frameworks. University of Illinois at Urbana-Champaign.
[30]
Jeffrey L Overbey and Ralph E Johnson. 2011. Differential precondition checking: A lightweight, reusable analysis for refactoring tools. In 2011 26th IEEE/ACM International Conference on Automated Software Engineering (ASE 2011). 303–312. https://doi.org/10.1109/ASE.2011.6100067
[31]
Replication Package. 2023. https://doi.org/10.5281/zenodo.8276904
[32]
ReSharper. 2023. https://www.jetbrains.com/resharper/
[33]
Don Roberts, John Brant, and Ralph Johnson. 1997. A refactoring tool for Smalltalk. Theory and Practice of Object systems, 3, 4 (1997), 253–263. https://doi.org/10.1002/(SICI)1096-9942(1997)3:4<253::AID-TAPO3>3.0.CO;2-T
[34]
Sample Size Calculator. 2023. https://www.surveysystem.com/sscalc.htm/
[35]
Max Schäfer and Oege de Moor. 2010. Specifying and implementing refactorings. In Proceedings of the 25th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2010, October 17-21, 2010, Reno/Tahoe, Nevada, USA. ACM, 286–301. https://doi.org/10.1145/1869459.1869485
[36]
Max Schäfer, Torbjörn Ekman, and Oege De Moor. 2008. Sound and extensible renaming for Java. In Proceedings of the 23rd ACM SIGPLAN conference on Object-oriented programming systems languages and applications (OOPSLA). 277–294. https://doi.org/10.1145/1449764.1449787
[37]
Emad Shihab, Ahmed E Hassan, Bram Adams, and Zhen Ming Jiang. 2012. An industrial study on the risk of software changes. In Proceedings of the ACM SIGSOFT 20th International Symposium on the Foundations of Software Engineering (FSE). 1–11. https://doi.org/10.1145/2393596.2393670
[38]
Suguru Shinotsuka, Naoyasu Ubayashi, Hideaki Shinomi, and Tetsuo Tamai. 2006. An extensible contract verifier for AspectJ. In Proceedings of the 2nd Asian Workshop on Aspect-Oriented Software Development (AOAsia 2)(Workshop at ASE 2006). 35–40.
[39]
Gustavo Soares, Rohit Gheyi, and Tiago Massoni. 2012. Automated behavioral testing of refactoring engines. IEEE Transactions on Software Engineering, 39, 2 (2012), 147–162. https://doi.org/10.1109/TSE.2012.19
[40]
Gustavo Soares, Rohit Gheyi, Dalton Serey, and Tiago Massoni. 2010. Making Program Refactoring Safer. IEEE Software, 27, 4 (2010), 52–57. https://doi.org/10.1109/MS.2010.63
[41]
Frank Tip, Robert M Fuhrer, Adam Kieżun, Michael D Ernst, Ittai Balaban, and Bjorn De Sutter. 2011. Refactoring using type constraints. ACM Transactions on Programming Languages and Systems, 33, 3 (2011), 1–47. https://doi.org/10.1007/978-3-540-74061-2_1
[42]
Frank Tip, Adam Kiezun, and Dirk Bäumer. 2003. Refactoring for generalization using type constraints. ACM SIGPLAN Notices, 38, 11 (2003), 13–26. https://doi.org/10.1145/949305.949308
[43]
Nikolaos Tsantalis, Theodoros Chaikalis, and Alexander Chatzigeorgiou. 2008. JDeodorant: Identification and removal of type-checking bad smells. In 2008 12th European conference on software maintenance and reengineering (CSMR). 329–331. https://doi.org/10.1109/CSMR.2008.4493342
[44]
Nikolaos Tsantalis and Alexander Chatzigeorgiou. 2009. Identification of move method refactoring opportunities. IEEE Transactions on Software Engineering, 35, 3 (2009), 347–367. https://doi.org/10.1109/TSE.2009.1
[45]
Nikolaos Tsantalis and Alexander Chatzigeorgiou. 2011. Identification of extract method refactoring opportunities for the decomposition of methods. Journal of Systems and Software, 84, 10 (2011), 1757–1782. issn:0164-1212 https://doi.org/10.1016/j.jss.2011.05.016
[46]
Nikolaos Tsantalis, Matin Mansouri, Laleh Eshkevari, Davood Mazinanian, and Danny Dig. 2018. Accurate and efficient refactoring detection in commit history. In 2018 IEEE/ACM 40th International Conference on Software Engineering (ICSE). 483–494. https://doi.org/10.1145/3180155.3180206
[47]
Nikolaos Tsantalis, Davood Mazinanian, and Giri Panamoottil Krishnan. 2015. Assessing the refactorability of software clones. IEEE Transactions on Software Engineering, 41, 11 (2015), 1055–1090. https://doi.org/10.1109/TSE.2015.2448531
[48]
Naoyasu Ubayashi, Jinji Piao, Suguru Shinotsuka, and Tetsuo Tamai. 2008. Contract-based verification for aspect-oriented refactoring. In 2008 1st International Conference on Software Testing, Verification, and Validation (ICST). 180–189. https://doi.org/10.1109/ICST.2008.36
[49]
Visual Studio. 2023. https://visualstudio.microsoft.com/
[50]
Michael Wahler, Uwe Drofenik, and Will Snipes. 2016. Improving Code Maintainability: A Case Study on the Impact of Refactoring. In 2016 IEEE International Conference on Software Maintenance and Evolution (ICSME). 493–501. https://doi.org/10.1109/ICSME.2016.52
[51]
Jiachen Yang, Keisuke Hotta, Yoshiki Higo, and Shinji Kusumoto. 2015. Towards purity-guided refactoring in Java. In 2015 IEEE International Conference on Software Maintenance and Evolution (ICSME). 521–525. https://doi.org/10.1109/ICSM.2015.7332506

Cited By

View all
  • (undefined)Automated Recommendation of Extracting Local Variable RefactoringsACM Transactions on Software Engineering and Methodology10.1145/3715110

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
ESEC/FSE 2023: Proceedings of the 31st ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering
November 2023
2215 pages
ISBN:9798400703270
DOI:10.1145/3611643
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 30 November 2023

Permissions

Request permissions for this article.

Check for updates

Badges

Author Tags

  1. Bugs
  2. Extract Local Variable
  3. Reliable
  4. Software Refactoring

Qualifiers

  • Research-article

Funding Sources

Conference

ESEC/FSE '23
Sponsor:

Acceptance Rates

Overall Acceptance Rate 112 of 543 submissions, 21%

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)115
  • Downloads (Last 6 weeks)2
Reflects downloads up to 20 Feb 2025

Other Metrics

Citations

Cited By

View all
  • (undefined)Automated Recommendation of Extracting Local Variable RefactoringsACM Transactions on Software Engineering and Methodology10.1145/3715110

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media