Refactoring Instances Detection in Software Development

Slide Note
Embed
Share

Refactoring is a key process in software development, involving changing the internal structure without altering external behavior. The benefits and challenges of refactoring, as well as the impact on development processes, are explored through research findings and observations from various studies.


Uploaded on Oct 06, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Detection of Rename Local Variable Refactoring Instances in Commit History Matin Mansouri Advisor: Dr. Nikolaos Tsantalis

  2. Refactoring 2

  3. The process of changing a software system in such a way that it does not alter the external behavior of the code, yet improves its internal structure 3

  4. A Frequent Activity Refactoring is done regularly [Murphy-Hill et al, TSE2012] Overall, about 16% of all the changes [Xing et al, ICSM2006] Developers consider refactoring an integral part of their programming [Ge et al, ICSE2014] 10% of development time is spent on refactoring [Kimet-al, TSE2014] 4

  5. A Beneficial Activity Microsoft study [Kimet-al, TSE2014]: Benefits observed from refactoring 30% improve maintainability 43% improved readability 27% add feature easier, improve extensibility, and fewer bugs When refactoring is performed 22% because of poor readability 13% code duplication 11% because of poor maintainability 5

  6. However Refactorings slow down code review [Ge et al, VLHCC2017] Globalrefactoringscan easily lead to merge conflicts [Dig et al, TSE2008] 80% of the breaking changes to the APIs are because of refactorings [Dig et al, ICSM2005] Refactorings affect negatively the process of accurately locating bug-introducing changes [Costa et al, TSE2016] 6

  7. But these can be mitigated if we could identify the applied refactorings 7

  8. Refactoring Detection to the Rescue Refactorings slow down code review [Ge et al, VLHCC2017] Refactoring-aware code review Globalchanges can easily lead to merge conflicts [Dig et al, TSE2008] Refactoring-aware code merging 80% of the breaking changes to the APIs are because of refactorings [Dig et al, ICSM2005] Refactoring-aware clientadaptation 8

  9. Refactoring Detection to the Rescue Refactorings affect negatively the process of accurately locating bug-introducing changes [Costa et al, TSE2016] Improving the accuracy of SZZ algorithm In addition Empirical studies showed contradicting results regarding the refactoring effect on the code [Soareset al, JSS2013] Precise tool for accurate studies 9

  10. Refactoring Detection: The processof identifying a set of refactoringsthat have been applied between two revisions of a software system 10

  11. Refactoring Detection Approaches RefactoringCrawler [Dig et al, ECOOP2006] Ref-Finder [Preteet al, ICSM2010] RefDiff [Silva et al, MSR2017] RefactoringMiner [Tsantaliset al, ICSE2018] Renaming detection [Malpohlet al, ASE2000] REPENT [Arnaoudovaet-al, TSE2014] 11

  12. However These approaches are incomplete Not all refactoring types are supported E.g., Rename Local Variable refactoring 12

  13. Why Rename Local Variable? Rename refactoring is the most applied refactoring (up to 74%) [Murphy-Hill et al, TSE2012] Rename local variable is the second most applied rename refactoring (~25%) [Arnaoudova et al, TSE2014] 21% developers do the rename refactoring everyday [Arnaoudovaet al, TSE2014] As important as other refactorings 13

  14. Refactoring Detection Approaches RefactoringCrawler [Dig et al, ECOOP2006] Rename Local Variable Ref-Finder [Preteet al, ICSM2010] No Support for RefDiff [Silva et al, MSR2017] RefactoringMiner [Tsantaliset al, ICSE2018] Renaming detection [Malpohlet al, ASE2000] Not Available REPENT [Arnaoudovaet-al, TSE2014] 14

  15. Rename Local Variable Detection is Difficult Extract/inline method B) after A) before 15

  16. Rename Local Variable Detection is Difficult Textual diff approach limitation public void invoke(...) { ... ClusterMessage imsg = manager. protected void sendSessionReplicationMessage(...) { String id = session.getIdInternal(); if (id != null) { ClusterMessage msg = manager.requestCompleted(id); if (msg != null) cluster.send(msg); } } requestCompleted(invalidIds[i]); if (imsg != null) cluster.send(imsg); ... if (session != null) id = session.getIdInternal(); if (id == null) return ... ClusterMessage msg = manager.requestCompleted(id); if (msg == null) return; cluster.send(msg); ... protected void sendInvalidSessions(...) { ClusterMessage imsg = if (imsg != null) cluster.send(imsg); manager.requestCompleted(invalidIds[i]); } } 16

  17. Rename Local Variable Detection is Difficult Merge and split variable 17

  18. Approach 18

  19. Approach RefactoringMiner for: Statement matching Support for other refactoring types (e.g., extract/inline/rename method) Rename local variable detection rules Statement matching post-processing 19

  20. RefactoringMiner Statement Matching: public dnsMessage sendAXFR(dnsMessage inMessage) { Socket s; ... dnsMessage outMessage; ... s.getOutputStream().write(out); outMessage = new dnsMessage(); public dnsMessage sendAXFR(dnsMessage query) { Socket s; ... dnsMessage response; ... s.getOutputStream().write(out); response = new dnsMessage(); outMessage-> response while (true) { while (true) { ... while (true) { response.addRecord(dns.ANSWER, r); } } return response; ... while (true) { outMessage.addRecord(dns.ANSWER, r); } } return outMessage; } } 21

  21. Rename Local Variable Rules There exists a replacement r which replaces the local variable l in the old revision with l in the new revision public dnsMessage sendAXFR(dnsMessage inMessage) { Socket s; ... dnsMessage outMessage; ... s.getOutputStream().write(out); outMessage = new dnsMessage(); public dnsMessage sendAXFR(dnsMessage query) { Socket s; ... dnsMessage response; ... s.getOutputStream().write(out); response = new dnsMessage(); while (true) { while (true) { ... while (true) { response.addRecord(dns.ANSWER, r); } } return response; ... while (true) { outMessage.addRecord(dns.ANSWER, r); } } return outMessage; } } 23

  22. Rename Local Variable Rules lshould belong to the declared local variables in maand l should belong to the declared local variables in ma' lshould not exist in the new revision of the code, and l should not exist in the old revision of the code public dnsMessage sendAXFR(dnsMessage inMessage) { Socket s; ... dnsMessage outMessage; ... s.getOutputStream().write(out); outMessage = new dnsMessage(); public dnsMessage sendAXFR(dnsMessage query) { Socket s; ... dnsMessage response; ... s.getOutputStream().write(out); response = new dnsMessage(); while (true) { while (true) { ... while (true) { response.addRecord(dns.ANSWER, r); } } return response; ... while (true) { outMessage.addRecord(dns.ANSWER, r); } } return outMessage; 24 } }

  23. Rename Local Variable Rules l should not appear in the body of the methods extracted from ma ,as detected by RefactoringMiner B) after A) before 25

  24. Rename Local Variable Rules A local variable cannot be renamed to two local variables Similarlytwo local variables cannot be renamed to one local variable 26

  25. Statement Matching Post-Processing Introducing scope public staticvoid main(String args[]) { if (args.get(0) == 0) { String errorMessage = args.get(1); saveError(errorMessage); } else { String message= args.get(1); saveResponse(message); } } public staticvoid main(String args[]) { if (args.get(0) == 0) { String response= args.get(1); saveError(response); } else { String response= args.get(1); saveResponse(response); } } 27

  26. RefactoringMiner Matches Statements in a Greedy Way 28

  27. Statement Matching Post-Processing Find an optimal match 30

  28. Evaluation 31

  29. Evaluation Research Questions: RQ1: How accurate is our technique in detecting instances of Rename Local Variable refactorings? RQ2: How does our technique perform compared to REPENT? RQ3: What is the efficiency of our technique in terms of the time taken for detecting instances of Rename Local Variable refactorings? 32

  30. Oracle Construction We used existing oracle provided by [Arnaoudovaet-al, TSE2014] Software Revisions Period Files Total File Revisions KLOC Detected Validated dnsjava 1998-2011 365 1,415 9-35 144 32 Tomcat 1999-2006 12,205 46,498 5-315 397 180 33

  31. RefBenchmark 34

  32. RefBenchmark Applications: Unify the results of different tools Compute agreement using two or more tools Evaluate the results of the tools against an oracle 35

  33. Extended Oracle Using RefBenchmark RefactoringMiner REPENT Software #Refactorings Agreed TP FP TP FP Tomcat 396 268 76 55 52 77 dnsjava 128 93 19 9 17 34 Total 524 361 95 64 69 111 37

  34. RQ1-Our Approach is Accurate Software #Refactorings TP FP FN Recall Precision Tomcat 396 344 55 52 86.9% 86.2% dnsjava 128 111 10 17 86.7% 91.7% Total 524 455 65 69 86.8% 87.5% 38

  35. RQ2-Comparison with REPENT RefactoringMiner REPENT Software #Refactorings Recall Precision Recall Precision Tomcat 396 86.9% 86.2% 80.8% 80.6% dnsjava 128 86.7% 91.7% 85.2% 75.7% Total 524 86.8% 87.5% 81.8% 79.3% 39

  36. RQ3-Execution Time(ms) 40

  37. Conclusion Provided a comprehensive rename local variable oracle The oracle is extended by 96 refactoring instances All detected instances are validated manually Added Rename local variable detection to RefactoringMiner Outperforms the state-of-the-art approach (REPENT) Introduced arefactoringresults agreement platform (RefBenchmark) 41

Related


More Related Content