[go: up one dir, main page]
More Web Proxy on the site http://driver.im/ skip to main content
10.1145/3510454.3516868acmconferencesArticle/Chapter ViewAbstractPublication PagesicseConference Proceedingsconference-collections
research-article

ReInstancer: automatically refactoring for instanceof pattern matching

Published: 19 October 2022 Publication History

Abstract

Pattern matching for instanceof is widely used with the advantage of conditionally extracting components from objects and with the disadvantage of the compulsory usage of type castings. The feature of pattern matching has been periodically previewed in the latest released version of JDK to avoid redundant type castings and to optimize pattern matching in multi-branch statements. Although pattern matching has many benefits, manual refactoring for instanceof pattern matching is time-consuming and tedious. Furthermore, no existing work can provide sufficient support for such refactoring. To this end, this paper presents a refactoring tool ReInstancer that mitigates and simplifies type castings by converting a multi-branch statement with instanceof pattern matching into a switch statement or expression automatically. ReInstancer is evaluated on 7 real-world applications, with a total of 4404 instanceof expressions. The evaluation results demonstrate that ReInstancer can successfully remove 2060 type castings and refactor 141 multi-branch statements with a total of 1972 instanceof pattern matching, which improves the code quality.

References

[1]
Eman Abdullah AlOmar, Mohamed Wiem Mkaouer, Ali Ouni, and Marouane Kessentini. 2019. Do design metrics capture developers perception of quality? an empirical study on self-affirmed refactoring activities. arXiv preprint arXiv:1907.04797 (2019).
[2]
Apache. 2014. Xalan. http://xalan.apache.org/xalan-j/
[3]
Apache. 2019. JBoss-Javassist. http://www.javassist.org/
[4]
Apache. 2020. The Apache Xerces™ Project - xerces.apache.org. http://xerces.apache.org/
[5]
Apache. 2021. Cassandra. https://cassandra.apache.org/
[6]
Apache. 2021. Fop. https://xmlgraphics.apache.org/fop/
[7]
Bela Ban. 2021. JGroups. http://www.jgroups.org/
[8]
Gavin Bierman. 2021. JEP 420: Pattern Matching for switch (Second Preview). https://openjdk.java.net/jeps/420
[9]
Danny Dig. 2010. A refactoring approach to parallelism. IEEE software 28, 1 (2010), 17--22.
[10]
Eclipse. 2021. Eclipse Java development tools. https://www.eclipse.org/jdt/
[11]
GPL. 2009. SLOCCount. http://www.dwheeler.com/sloccount/
[12]
Mark Grechanik, Collin McMillan, Luca DeFerrari, Marco Comi, Stefano Crespi, Denys Poshyvanyk, Chen Fu, Qing Xie, and Carlo Ghezzi. 2010. An empirical investigation into a large-scale Java open source code repository. In Proceedings of the 2010 ACM-IEEE International Symposium on Empirical Software Engineering and Measurement. 1--10.
[13]
Hypersonic SQL Group. 2021. HSQLDB - 100% Java Database. http://hsqldb.org/
[14]
Alex Gyori, Lyle Franklin, Danny Dig, and Jan Lahoda. 2013. Crossing the gap from imperative to functional programming through refactoring. In Proceedings of the 2013 9th Joint Meeting on Foundations of Software Engineering. 543--553.
[15]
IBM. 2021. The t. j. watson libraries for analysis. http://wala.sourceforge.net/wiki/index.php/Main_Pag
[16]
Siim Karus and Harald Gall. 2011. A study of language usage evolution in open source software. In Proceedings of the 8th Working Conference on Mining Software Repositories. 13--22.
[17]
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). IEEE, 224--235.
[18]
Yu Lin, Cosmin Radoi, and Danny Dig. 2014. Retrofitting concurrency for android applications through refactoring. In Proceedings of the 22nd ACM SIGSOFT International Symposium on Foundations of Software Engineering. 341--352.
[19]
Semih Okur, David L Hartveld, Danny Dig, and Arie van Deursen. 2014. A study and toolkit for asynchronous programming in C#. In Proceedings of the 36th International Conference on Software Engineering. 1117--1127.
[20]
Chris Parnin, Christian Bird, and Emerson Murphy-Hill. 2013. Adoption and use of Java generics. Empirical Software Engineering 18, 6 (2013), 1047--1089.
[21]
R Robbes, E Tanter, and D Rothlisberger. 2011. How developers use the dynamic features of programming languages: the case of smalltalk. In Proceedings of the International Working Conference on Mining Software Repositories, Vol. 10.
[22]
Campwood Software. 2021. SourceMonitor. https://www.campwoodsw.com/sourcemonitor.html
[23]
M Wang, J Gibbons, K Matsuda, and Z Hu. 2013. Refactoring Pattern Matching. Science of Computer Programming 78, 11 (2013), 2216--2242.
[24]
Yang Zhang and Chunhao Dong. 2021. MARS: Detecting Brain Class/Method Code Smell Based on Metric-Attention Mechanism and Residual Network. In Journal of Software: Evolution and Process.
[25]
Yang Zhang, Shicheng Dong, Xiangyu Zhang, Huan Liu, and Dongwen Zhang. 2019. Automated refactoring for stampedlock. IEEE Access 7 (2019), 104900--104911.
[26]
Yang Zhang, Chaoshuai Li, and Shuai Shao. 2021. ReSwitcher: Automatically Refactoring Java Programs for Switch Expression. 2021 IEEE International Symposium on Software Reliability Engineering Workshops (ISSREW) (2021), 400--401.
[27]
Yang Zhang, Shuai Shao, Juan Zhai, and Shiqing Ma. 2020. FineLock: automatically refactoring coarse-grained locks into fine-grained locks. In Proceedings of the 29th ACM SIGSOFT International Symposium on Software Testing and Analysis. 565--568.

Cited By

View all
  • (2024)ExceRef: Automatically Refactoring for Exception HandlingProceedings of the 15th Asia-Pacific Symposium on Internetware10.1145/3671016.3674824(239-248)Online publication date: 24-Jul-2024
  • (2024) ReInstancer: An automatic refactoring approach for Instanceof pattern matching Journal of Software: Evolution and Process10.1002/smr.2661Online publication date: 12-Mar-2024

Index Terms

  1. ReInstancer: automatically refactoring for instanceof pattern matching

    Recommendations

    Comments

    Please enable JavaScript to view thecomments powered by Disqus.

    Information & Contributors

    Information

    Published In

    cover image ACM Conferences
    ICSE '22: Proceedings of the ACM/IEEE 44th International Conference on Software Engineering: Companion Proceedings
    May 2022
    394 pages
    ISBN:9781450392235
    DOI:10.1145/3510454
    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

    In-Cooperation

    • IEEE CS

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 19 October 2022

    Permissions

    Request permissions for this article.

    Check for updates

    Author Tags

    1. instanceof
    2. pattern matching
    3. program analysis
    4. refactoring
    5. switch expression

    Qualifiers

    • Research-article

    Conference

    ICSE '22
    Sponsor:

    Acceptance Rates

    Overall Acceptance Rate 276 of 1,856 submissions, 15%

    Upcoming Conference

    ICSE 2025

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • Downloads (Last 12 months)10
    • Downloads (Last 6 weeks)1
    Reflects downloads up to 31 Dec 2024

    Other Metrics

    Citations

    Cited By

    View all
    • (2024)ExceRef: Automatically Refactoring for Exception HandlingProceedings of the 15th Asia-Pacific Symposium on Internetware10.1145/3671016.3674824(239-248)Online publication date: 24-Jul-2024
    • (2024) ReInstancer: An automatic refactoring approach for Instanceof pattern matching Journal of Software: Evolution and Process10.1002/smr.2661Online publication date: 12-Mar-2024

    View Options

    Login options

    View options

    PDF

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    Media

    Figures

    Other

    Tables

    Share

    Share

    Share this Publication link

    Share on social media