ReInstancer:针对 Instanceof 模式匹配的自动重构方法

IF 1.7 4区 计算机科学 Q3 COMPUTER SCIENCE, SOFTWARE ENGINEERING
Yang Zhang, Shuai Hong
{"title":"ReInstancer:针对 Instanceof 模式匹配的自动重构方法","authors":"Yang Zhang,&nbsp;Shuai Hong","doi":"10.1002/smr.2661","DOIUrl":null,"url":null,"abstract":"<p>The <i>instanceof</i> 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 <i>instanceof</i> 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 <i>ReInstancer</i> to refactor <i>instanceof</i> pattern matching automatically. <i>ReInstancer</i> 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 <i>switch</i> statements or expressions. <i>ReInstancer</i> is evaluated by 20 real-world projects with more than 7,700 <i>instanceof</i> pattern matching. The experimental results demonstrate that a total of 3,558 <i>instanceof</i> expressions and 228 multi-branch statements are refactored within 10.8 s on average for each project. <i>ReInstancer</i> improves the code quality by reducing redundant typecasting, demonstrating its effectiveness.</p>","PeriodicalId":48898,"journal":{"name":"Journal of Software-Evolution and Process","volume":"36 8","pages":""},"PeriodicalIF":1.7000,"publicationDate":"2024-03-12","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":"{\"title\":\"ReInstancer: An automatic refactoring approach for Instanceof pattern matching\",\"authors\":\"Yang Zhang,&nbsp;Shuai Hong\",\"doi\":\"10.1002/smr.2661\",\"DOIUrl\":null,\"url\":null,\"abstract\":\"<p>The <i>instanceof</i> 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 <i>instanceof</i> 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 <i>ReInstancer</i> to refactor <i>instanceof</i> pattern matching automatically. <i>ReInstancer</i> 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 <i>switch</i> statements or expressions. <i>ReInstancer</i> is evaluated by 20 real-world projects with more than 7,700 <i>instanceof</i> pattern matching. The experimental results demonstrate that a total of 3,558 <i>instanceof</i> expressions and 228 multi-branch statements are refactored within 10.8 s on average for each project. <i>ReInstancer</i> improves the code quality by reducing redundant typecasting, demonstrating its effectiveness.</p>\",\"PeriodicalId\":48898,\"journal\":{\"name\":\"Journal of Software-Evolution and Process\",\"volume\":\"36 8\",\"pages\":\"\"},\"PeriodicalIF\":1.7000,\"publicationDate\":\"2024-03-12\",\"publicationTypes\":\"Journal Article\",\"fieldsOfStudy\":null,\"isOpenAccess\":false,\"openAccessPdf\":\"\",\"citationCount\":\"0\",\"resultStr\":null,\"platform\":\"Semanticscholar\",\"paperid\":null,\"PeriodicalName\":\"Journal of Software-Evolution and Process\",\"FirstCategoryId\":\"94\",\"ListUrlMain\":\"https://onlinelibrary.wiley.com/doi/10.1002/smr.2661\",\"RegionNum\":4,\"RegionCategory\":\"计算机科学\",\"ArticlePicture\":[],\"TitleCN\":null,\"AbstractTextCN\":null,\"PMCID\":null,\"EPubDate\":\"\",\"PubModel\":\"\",\"JCR\":\"Q3\",\"JCRName\":\"COMPUTER SCIENCE, SOFTWARE ENGINEERING\",\"Score\":null,\"Total\":0}","platform":"Semanticscholar","paperid":null,"PeriodicalName":"Journal of Software-Evolution and Process","FirstCategoryId":"94","ListUrlMain":"https://onlinelibrary.wiley.com/doi/10.1002/smr.2661","RegionNum":4,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"Q3","JCRName":"COMPUTER SCIENCE, SOFTWARE ENGINEERING","Score":null,"Total":0}
引用次数: 0

摘要

instanceof 模式匹配可以去除多余的类型转换,简化不同场景下的设计,从而提高代码质量和可读性。然而,现有的工作并没有为重构 instanceof 模式匹配提供足够的支持。本文首先确定了现有集成开发环境无法很好处理的几种情况。基于这些观察结果,我们提出了一种名为 ReInstancer 的新方法,用于自动重构 instanceof 模式匹配。ReInstancer 对多分支语句进行程序分析,以获取模式变量。分析这些模式后,多分支语句将被优化,并最终重构为开关语句或表达式。ReInstancer 在 20 个实际项目中进行了评估,模式匹配实例超过 7,700 个。实验结果表明,每个项目平均在 10.8 秒内重构了 3,558 个 instanceof 表达式和 228 个多分支语句。ReInstancer 通过减少冗余类型铸造提高了代码质量,证明了它的有效性。
本文章由计算机程序翻译,如有差异,请以英文原文为准。

ReInstancer: An automatic refactoring approach for Instanceof pattern matching

ReInstancer: An automatic refactoring approach for Instanceof pattern matching

ReInstancer: An automatic refactoring approach for Instanceof pattern matching

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.

求助全文
通过发布文献求助,成功后即可免费获取论文全文。 去求助
来源期刊
Journal of Software-Evolution and Process
Journal of Software-Evolution and Process COMPUTER SCIENCE, SOFTWARE ENGINEERING-
自引率
10.00%
发文量
109
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
确定
请完成安全验证×
copy
已复制链接
快去分享给好友吧!
我知道了
右上角分享
点击右上角分享
0
联系我们:info@booksci.cn Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。 Copyright © 2023 布克学术 All rights reserved.
京ICP备2023020795号-1
ghs 京公网安备 11010802042870号
Book学术文献互助
Book学术文献互助群
群 号:481959085
Book学术官方微信