1ACTIVE SUPPORTFOR CLONE REFACTORING:A PERSPECTIVE	
Norihiro Yoshida (Nara Institute of Science and Technology)
Eunjong Choi (Osaka University)
Katsuro Inoue (Osaka University)

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

2Outline	• Clone and its refactoring• Previous research• Industrial experience in active clone refactoring• Research proposal• Plan towards proactive support for clone refactoring• Summary	3What is Code Clone ?	
A code fragment that has similar or
identical part in source code	Bug isfound	Necessaryto inspect
themCode Clone	If we modify one of them, it is necessary to determine
whether or not we have to modify the others.

Clone Refactoring	Merging clones into a single program unit.
RemoveCode Clones	

Merging	call	Old VersionNew Version45Clone Detection Tool : CCFinder [1]	• A token-based clone detection tool
• Transform source code into sequence of tokens• Detect identical parts of the sequence as code clones• Scalable and accurate

Output	Input	

Source Files

CCFinderLocation Informationof Code Clone[1] T. Kamiya, S. Kusumoto, and K. Inoue, “CCFinder: A multilinguistic token-based code clone detection
system for large scale source code”, IEEE Transactions on Software Engineering, 28(7):654-670, 2002.

6

Industrial Experience in Clone Analysis	• Only hot clones can be refactored.
• Strike while the iron is hot!

• In industry, cost of clone refactoring cannot be ignored.
• Regression test after refactoring takes much cost to preserve

behavior after refactoring.
• Industrial developers do not touch source code after large-scale

system test for releasing major version.

Active support of clone refactoring is needed
to notify newly-appeared clones regularly to developers.	

7Clone Notifier :A Clone Change Management System [2]	Version ControlSystemCommit
source code	Developer	Checkout
source code	
Identification ofClone Evolution	
Clone Notifier

Report clone evolution information• E-mail notification• Web-based UI	

[2] Yamanaka, et al.: "Applying Clone Change Notification System into an Industrial
Development Process", ICPC 2013.	

8

Applying to Industrial Process	• Applied Clone Notifier to development process in NEC• 6 programmers, 120 KLOC written in Java

• Got regular feedbacks from a project manager
Questionnaire	

Daily Report	

Clone NotifierProjectmanager

Feedback	
Our group10 sets of code clones were recognized
as refactoring opportunities in 40 days.	

9Towards More Active Support	
• Related Work: Proactive Support for Refactoring• Benefactor[2] and WitichDoctor[3] detect the beginning ofrefactoring, and recommend code transformations to complete it.

• In the case of clone refactoring, existing tools

lacks proactive support• There is no tool that supports clone refactoring based on the online

analysis of code modification.

[3] Foster et al: WitchDoctor: IDE Support for Real-Time Auto-Completionof Refactorings, ICSE 2012.
[4] Ge et al: Reconciling manual and automatic refactoring, ICSE 2012.	

10

Proactive Refactoring Candidate Detection
Overview	
• We plan to develop an Eclipse plug-in for proactive

refactoring candidate detection.
• The detection is based on the online analysis of code modification.

Code modification
for refactoring	 Online detection ofrefactorings	

developer	 clone refactoringscandidates

Inference of clone
refactoring
candidates	

11

Proactive Candidate Detection for Clone Refactoring
Key Idea	When a developer refactors a code fragment, he/she has toconsider to refactor the clones of the code fragment.
Developer	Extract Method
Clone	New method	

Clone	Clone			Also consider to perform
Extract Method

If IDE catches the beginning of clone refactoring,it can proactively recommend clones to be refactored at once.

12

Proactive Candidate Detection for Clone Refactoring
Step1: Refactoring detection	
Developer	Clone	
Clone	New method	Once he extracts
a clone as a new
method …
Tool	

Clone	

Tool detects the beginningof the refactoring

13

Proactive Candidate Detection for Clone Refactoring
Step2: Clone detection	

Clone	New method	

Clone	
Tool	
Clone	

Tool identifies
the corresponding clones.

14

Proactive Candidate Detection for Clone Refactoring
Step3: Recommendation of refactoring candidates	

Clone	New method	

Clone	
Tool	Clone	Tool recommends tomerge those clones into
the new method.

15

Other Challenges for Proactive Supportfor Clone Refactoring	• Near real time clone detection• Invoked by modification in a source code editor• Finish the detection by the timing of next modification.
• Precise detection of refactoring candidate selection• Clones are not always refactoring candidates• Syntactically incomplete clone• Clone accidentally created by only the replacement of statements.

• Discovering further heuristics is needed for eliminatingclones that should not be detected.

16Summary	• We discussed active and proactive support

for clone refactoring• Industrial experience in active support for clonerefactoring• Plan for developing tool that supports clone refactoring

proactively• Currently, we are developing a prototype tool that

supports clone refactoring proactively.