Refactoring Instances Detection in Software Development

Detection of
Rename Local Variable Refactoring Instances
 in
Commit History
Matin Mansouri
Advisor: Dr
.
 Nikolaos Tsantalis
Refactoring
2
The process of
changing a software system
in such a way that
i
t does not alter the external behavior
of the code,
yet
 
improves its internal structure
3
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 
[
Kim
 et-al, TSE2014]
4
A 
Beneficial 
Activity
 
Microsoft study 
[
Kim
 et-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
However
6
 
Refactorings slow down code review 
[Ge et al, VLHCC2017]
G
lobal 
refactorings 
can 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]
But these can be mitigated if we
could 
identify
 the applied
refactorings
7
Refactoring Detection to the Rescue
 
Refactorings slow down code review 
[Ge et al, VLHCC2017]
Refactoring-aware code review
 
G
lobal changes can easily lead to merge conflicts
 
[Dig et al, TSE2008]
Refactoring-aware c
ode merging
 80% of the breaking changes to the APIs are because of
refactorings
 
[Dig et al, ICSM2005]
Refactoring-aware c
lient adaptation
 
8
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 
[Soares et al, JSS2013]
Precise tool for accurate studies
9
Refactoring Detection:
 
The process
 of identifying a set of refactorings that
have been applied between two revisions of a
software system
 
10
Refactoring Detection Approaches
 
RefactoringCrawler 
[Dig et al,  ECOOP2006]
Ref-Finder 
[Prete et al, ICSM2010]
RefDiff 
[Silva et al, MSR2017]
RefactoringMiner 
[Tsantalis et al, ICSE2018]
Renaming detection 
[Malpohl et al, ASE2000]
REPENT 
[Arnaoudova et-al, TSE2014]
 
11
However
12
 
These approaches are incomplete
Not all refactoring types are supported
E.g., Rename Local Variable refactoring
 
 
Why Rename Local Variable
?
 
Rename refactoring is the most applied refactoring (up to
74%) 
[Murphy-Hill et al, TSE2012]
R
ename local variable is the 
second most applied
 rename
refactoring (~25%)
 [Arnaoudova et al, TSE2014]
21% developers do the rename refactoring everyday 
[Arnaoudova et
al, TSE2014]
As important as other refactorings
 
 
13
Refactoring Detection Approaches
RefactoringCrawler 
[Dig et al,  ECOOP2006]
Ref-Finder 
[Prete et al, ICSM2010]
RefDiff 
[Silva et al, MSR2017]
RefactoringMiner 
[Tsantalis et al, ICSE2018]
Renaming detection 
[Malpohl et al, ASE2000]
REPENT 
[Arnaoudova et-al, TSE2014]
14
 
No Support for
Rename Local Variable
 
Not Available
Rename Local Variable Detection is Difficult
 
Extract/inline method
15
 
A) before
 
B) after
Rename Local Variable Detection is Difficult
 
Textual diff approach limitation
16
 
public void 
invoke(
...
) {
    
...
    ClusterMessage 
imsg
 = 
manager
.
 
    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 
sendSessionReplicationMessage(
...
) {
    
String 
id
 = 
session
.getIdInternal();
    
if
 (
id
 != null) {
        ClusterMessage 
msg
 = 
manager
.requestCompleted(
id
);
        
if
 (
msg
 != 
null
)
            
cluster
.send(
msg
);
    }
}
protected void 
sendInvalidSessions(.
..
) {
   ClusterMessage 
imsg 
= 
 
manager
.requestCompleted(
invalidIds
[
i
]);
   
if
 (
imsg
 != 
null
)
       
cluster
.send(
imsg
);
}
Rename Local Variable Detection is Difficult
 
Merge and split variable
17
Approach
18
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
RefactoringMiner
Statement Matching:
20
 
Statement Matching:
 
public
 dnsMessage sendAXFR(dnsMessage 
inMessage
) {
        Socket 
s
;
        
...
        dnsMessage 
outMessage
;
        
...
        
s
.getOutputStream().write(
out
);
        
outMessage
 = 
new
 dnsMessage();
        
while
 (
true
) {
 
...
            
while
 (
true
) {
                
outMessage
.addRecord(
dns
.
ANSWER
, 
r
);
            }
        }
        
return
 
outMessage
;
    }
 
public
 dnsMessage sendAXFR(dnsMessage 
query
) {
        Socket 
s
;
        
...
        dnsMessage 
response
;
        
...
        
s
.getOutputStream().write(
out
);
        
response
 = 
new
 dnsMessage();
        
while
 (
true
) {
            ...
            
while
 (
true
) {
                
response
.addRecord(
dns
.
ANSWER
, 
r
);
            }
        }
        
return
 
response
;
    }
RefactoringMiner
outMessage -> response
21
Rename Local Variable Rules
There exists a method 
m
a’
 in the new revision of the code that was matched
with 
m
a
public
 dnsMessage sendAXFR(dnsMessage 
inMessage
) {
        Socket 
s
;
        
...
        dnsMessage 
outMessage
;
        
...
        
s
.getOutputStream().write(
out
);
        
outMessage
 = 
new
 dnsMessage();
        
while
 (
true
) {
 
...
            
while
 (
true
) {
                
outMessage
.addRecord(
dns
.
ANSWER
, 
r
);
            }
        }
        
return
 
outMessage
;
    }
public
 dnsMessage sendAXFR(dnsMessage 
query
) {
        Socket 
s
;
        
...
        dnsMessage 
response
;
        
...
        
s
.getOutputStream().write(
out
);
        
response
 = 
new
 dnsMessage();
        
while
 (
true
) {
            ...
            
while
 (
true
) {
                
response
.addRecord(
dns
.
ANSWER
, 
r
);
            }
        }
        
return
 
response
;
    }
22
 
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 
query
) {
        Socket 
s
;
        
...
        dnsMessage 
response
;
        
...
        
s
.getOutputStream().write(
out
);
        
response
 = 
new
 dnsMessage();
        
while
 (
true
) {
            ...
            
while
 (
true
) {
                
response
.addRecord(
dns
.
ANSWER
, 
r
);
            }
        }
        
return
 
response
;
    }
 
public
 dnsMessage sendAXFR(dnsMessage 
inMessage
) {
        Socket 
s
;
        
...
        dnsMessage 
outMessage
;
        
...
        
s
.getOutputStream().write(
out
);
        
outMessage
 = 
new
 dnsMessage();
        
while
 (
true
) {
 
...
            
while
 (
true
) {
                
outMessage
.addRecord(
dns
.
ANSWER
, 
r
);
            }
        }
        
return
 
outMessage
;
    }
Rename Local Variable Rules
23
 
l
 should belong to the declared local variables in 
m
a
 
and 
l
 
should belong to the
declared local variables in 
m
a
'
l
 should 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 
query
) {
        Socket 
s
;
        
...
        dnsMessage 
response
;
        
...
        
s
.getOutputStream().write(
out
);
        
response
 = 
new
 dnsMessage();
        
while
 (
true
) {
            ...
            
while
 (
true
) {
                
response
.addRecord(
dns
.
ANSWER
, 
r
);
            }
        }
        
return
 
response
;
}
 
public
 dnsMessage sendAXFR(dnsMessage 
inMessage
) {
        Socket 
s
;
        
...
        dnsMessage 
outMessage
;
        
...
        
s
.getOutputStream().write(
out
);
        
outMessage
 = 
new
 dnsMessage();
        
while
 (
true
) {
 
...
            
while
 (
true
) {
                
outMessage
.addRecord(
dns
.
ANSWER
, 
r
);
            }
        }
        
return
 
outMessage
;
}
Rename Local Variable Rules
24
Rename Local Variable Rules
 
l
 should not appear in the body of the methods extracted from 
m
a 
,as
detected by RefactoringMiner
25
 
A) before
 
B) after
Rename Local Variable Rules
 
A local variable cannot be renamed to two local variables
Similarly
 two local variables 
cannot be 
renamed to one local variable
26
 
Introducing scope
 
public
 
static
 
void
 main(String 
args
[]) {
    
if
 (
args
.get(0) == 0) {
        String 
errorMessage
 = 
args
.get(1);
        saveError(
errorMessage
);
    } 
else
 {
        String 
message
 = 
args
.get(1);
        saveResponse(
message
);
    }
}
 
public
 
static
 
void
 main(String 
args
[]) {
    
if
 (
args
.get(0) == 0) {
        String 
response
 = 
args
.get(1);
        saveError(
response
);
    } 
else
 {
        String 
response
 = 
args
.get(1);
        saveResponse(
response
);
    }
}
Statement Matching Post-Processing
27
RefactoringMiner Matches
Statements in a Greedy Way
28
Rename Local Variable Exception
 
Exception of the rules:
A variable can have two matches in the target if:
They belong to different scopes
One of the matches is not optimal
29
Statement Matching Post-Processing
 
Find an optimal match
30
Evaluation
31
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
Oracle Construction
We used existing oracle provided by [Arnaoudova et-al, TSE2014]
33
RefBenchmark
34
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
36
Extended Oracle
37
Using RefBenchmark
RQ1-
Our 
Approach 
is Accurate
38
RQ2-Comparison with REPENT
39
RQ3-Execution Time
 (ms)
40
Conclusion
 
Provided a comprehensive
 rename local variable oracle
The oracle is extended by 96 refactoring instances
All detected instances are validated manually
Add
ed
 Rename local variable detection to RefactoringMiner
Outperform
s
 the state-of-the-art approach (REPENT)
Introduced a
 refactoring
 
results 
agreement platform
(RefBenchmark)
 
41
Slide Note

Date department

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.

  • Refactoring
  • Software Development
  • Code Review
  • Maintainability
  • Code Refactoring

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.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

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.

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

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#