ReInstancer: An automatic refactoring approach for Instanceof pattern matching

Author:

Zhang Yang1ORCID,Hong Shuai2

Affiliation:

1. School of Information Science and Engineering Hebei University of Science and Technology Shijiazhuang Hebei China

2. College of Information Science and Technology Dalian Maritime University Dalian Liaoning China

Abstract

AbstractThe instanceof pattern matching can improve the code quality and readability by removing the redundant typecasting and simplifying the design in different scenarios. However, existing works do not provide sufficient support for refactoring instanceof pattern matching. This paper first identifies several cases that cannot be well handled by existing IDEs. Based on these observations, we propose a novel approach called ReInstancer to refactor instanceof pattern matching automatically. ReInstancer conducts program analysis for multi‐branch statements to obtain pattern variables. After analyzing these patterns, the multi‐branch statements are optimized and finally refactored into switch statements or expressions. ReInstancer is evaluated by 20 real‐world projects with more than 7,700 instanceof pattern matching. The experimental results demonstrate that a total of 3,558 instanceof expressions and 228 multi‐branch statements are refactored within 10.8 s on average for each project. ReInstancer improves the code quality by reducing redundant typecasting, demonstrating its effectiveness.

Funder

Natural Science Foundation of Hebei Province

Publisher

Wiley

Reference59 articles.

1. BiermanG.JEP 420: pattern matching for switch (second preview);2021.https://openjdk.java.net/jeps/420.

2. Refactoring pattern matching

3. JMatch: Iterable Abstract Pattern Matching for Java

4. CantatoreA.Wildcard matching algorithms;2003.https://xoomer.virgilio.it/acantato/dev/wildcard/wildmatch.html.

5. Automated Refactoring for Stampedlock

同舟云学术

1.学者识别学者识别

2.学术分析学术分析

3.人才评估人才评估

"同舟云学术"是以全球学者为主线,采集、加工和组织学术论文而形成的新型学术文献查询和分析系统,可以对全球学者进行文献检索和人才价值评估。用户可以通过关注某些学科领域的顶尖人物而持续追踪该领域的学科进展和研究前沿。经过近期的数据扩容,当前同舟云学术共收录了国内外主流学术期刊6万余种,收集的期刊论文及会议论文总量共计约1.5亿篇,并以每天添加12000余篇中外论文的速度递增。我们也可以为用户提供个性化、定制化的学者数据。欢迎来电咨询!咨询电话:010-8811{复制后删除}0370

www.globalauthorid.com

TOP

Copyright © 2019-2024 北京同舟云网络信息技术有限公司
京公网安备11010802033243号  京ICP备18003416号-3