loading page

ReInstancer: An Automatic Refactoring Approach for Instancerof Pattern Matching
  • Yang Zhang,
  • AR TI CLE
Yang Zhang
Hebei University of Science and Technology

Corresponding Author:[email protected]

Author Profile
AR TI CLE
Hebei University of Science and Technology
Author Profile

Abstract

The extit{instanceof} pattern matching is periodically previewed in the latest published JDK by removing the redundant casting and optimizing its usage in different scenarios, which improves the code quality and readability. However, the existing integrated development environment (IDE) does not provide sufficient support for refactoring of extit{instanceof} pattern matching in all situations. This paper first identifies several cases that cannot be handled by existing IDEs, and then proposes a novel approach called extit{ReInstancer} to refactor extit{instanceof} pattern matching automatically. extit{ReInstancer} conducts visitor pattern analysis for extit{if} statement blocks with extit{instanceof}. For the extit{instanceof} expression, a pattern variable is obtained after removing the redundant type casting by pattern analysis. For multi-branch statements, extit{ReInstancer} employs class hierarchy analysis and control flow analysis to infer the relationship of instance type in each branch and then optimize these branches. Finally, the multi-branch statements are converted into switch statements or switch expressions. extit{ReInstancer} is evaluated with 20 real-world applications. The experimental results demonstrate a total of 3558 extit{instanceof} expressions and 228 multi-branch statements applying the refactoring, and each application takes an average of 10.8s. extit{ReInstancer} not only reduces the redundant type casting but also improves the code quality.
02 Jan 2023Submitted to Journal of Software: Evolution and Process
08 Jan 2023Submission Checks Completed
08 Jan 2023Assigned to Editor
04 Apr 2023Reviewer(s) Assigned
11 Jun 2023Review(s) Completed, Editorial Evaluation Pending
11 Aug 2023Editorial Decision: Revise Major
27 Sep 20231st Revision Received
28 Sep 2023Submission Checks Completed
28 Sep 2023Assigned to Editor
09 Nov 2023Reviewer(s) Assigned
20 Feb 2024Submission Checks Completed
20 Feb 2024Assigned to Editor
20 Feb 2024Review(s) Completed, Editorial Evaluation Pending
20 Feb 2024Editorial Decision: Accept