当前位置: X-MOL 学术J. Softw. Evol. Process › 论文详情
Our official English website, www.x-mol.net, welcomes your feedback! (Note: you will need to create a separate account there.)
ReInstancer: An automatic refactoring approach for Instanceof pattern matching
Journal of Software: Evolution and Process ( IF 2 ) Pub Date : 2024-03-12 , DOI: 10.1002/smr.2661
Yang Zhang 1 , Shuai Hong 2
Affiliation  

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

中文翻译:

ReInstancer:一种用于 Instanceof 模式匹配的自动重构方法

实例化模式匹配可以通过消除冗余类型转换并简化不同场景下的设计来提高代码质量和可读性。然而,现有的工作并没有为重构提供足够的支持实例化模式匹配。本文首先指出了现有 IDE 无法很好处理的几种情况。基于这些观察,我们提出了一种新方法,称为重新实例化器重构实例化自动模式匹配。重新实例化器对多分支语句进行程序分析,获取模式变量。分析这些模式后,对多分支语句进行优化,最终重构为转变陈述或表达。重新实例化器由 20 个实际项目进行评估,涉及 7,700 多个项目实例化模式匹配。实验结果表明,总共有 3,558 个实例化每个项目平均在 10.8 秒内重构表达式和 228 个多分支语句。重新实例化器通过减少冗余类型转换来提高代码质量,证明其有效性。
更新日期:2024-03-12
down
wechat
bug