{"title":"ReInstancer:针对 Instanceof 模式匹配的自动重构方法","authors":"Yang Zhang, 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, 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}
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.