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
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