1
play

1 Research Goal Proposed tool: Chained clone detection tool - PDF document

Overview of my presentation Introduction of chained clone detection Detection of Chained Clone and Its Application N.Yoshida, et al.: "On Refactoring Support Based on Code Clone Dependency Relation", Proc. of METRICS 2005.


  1. Overview of my presentation � Introduction of chained clone detection Detection of Chained Clone and Its Application � N.Yoshida, et al.: "On Refactoring Support Based on Code Clone Dependency Relation", Proc. of METRICS 2005. Norihiro Yoshida � Basically, it is proposed for refactoring support y, p p g pp NAIST / Osaka University, Japan � Discussion on other application of chained clone detection � We would like to try to apply chained clone detection into supporting other software maintenance activity. 1 2 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Refactoring Difficulty of Refactoring � Refactoring[1] is a way to deal with code clone problem. � It is difficult to identity refactoring opportunities in � Refactoring is a technique for restructuring an existing large scale source code. code � Alter software’s internal structure without changing its external � Where are code fragments that should be merged behavior into one method? � Improve the maintainability of software � Number one in the stink parade is duplicate code � How should they be merged into one method? � How should they be merged into one method? � Extract Method or Pull Up Method Refactroing? New method New Call statements method Call statements [1] M. Fowler, Refactoring: improving the design of existing code, Addison Wesley, 1999 Extract Method Refactoring Pull Up Method Refactoring 3 4 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Token-based clone detection for refactoring support Token-based clone detection for refactoring support (1/2) (2/2) � In many cases, Type2 clone refactoring is easier than Type3 � Basically, a set of type2 clones DO NOT have one. semantic similarity. � Type2 clone set is consist of continuous token sequences � However, target clones for Extract Method or Pull-up � it is easy to merge it into one module. Method should be semantic unit. � Type3 clone refactoring is comprised of more complicated � In this context, semantic clone detection is more � In this context, semantic clone detection is more steps steps suitable for refactoring support. � It needs to solve syntax differences between code fragments. � Most token-based clone detection tools (e.g., CCFinder) DO NOT perform inter-procedural � Scalability of detection analysis. � Token-based clone detection tool is more scalable than syntax-based or semantic-based tools � One functionality is sometimes implemented by a chain of methods. 5 6 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1

  2. Research Goal Proposed tool: Chained clone detection tool � Detection of clone sets connected by callee-caller relations � Define a set of clone sets having callee-caller relations as a chained clone � Scalable detection by analyzing only code fragments in � Suggest applicable refactoring pattern for each chained CCFInder’s output clone based on chained clone categorization � Call-caller relations are inferred by static analysis Chained Clone Those are semantically similar, and often imply the i il d f i l h A pair of chained clones Method a1 Method a2 same functionality . clone set A Method a1 Method a2 It is a better refactoring call opportunity than each type2 call Method b1 Method b2 clone set. clone set B Method b1 Method b2 call call It is easy to merge each type2 Method c1 Method c2 clone set C Method c1 Method c2 clone set into one module. 7 8 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Definition of chained clone(1) Definition of chained clone(2) � Chained Method � Chained Clone CM1 CM2 A set of methods that hold callee-caller � � For 2 given chained methods CM1 and relations CM2, we transform them into chained method graphs G1 and G2. � Chained Method Graph A Chained Method � For G1 and G2, if the following three conditions are satisfied, we call the pair A node represents a method A node represents a method � � of CM1 and CM2 as a chained clone. G1 G2 � An edge represents a callee-caller 1. G1 and G2 are isomorphic. Call Call relation Call Call Call Call 2. Each pair of the corresponding nodes between G1 and G2, holds a Call Call Call Call clone relation. Call Call A pair of nodes filled � Chained Clone Set with colored same A Chained Method Graph color is a code clone � An equivalence class of chained clones 9 10 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Typical Chained Clones Applicable Refactorings for Chained Clones Case 1 : Extract Method Refactoring � The following refactoring[1] can be applied to merge � All the methods in a chained clone that are contained in a single class. chained clones. Before Refactoring After Refactoring � Pull Up Method Refactoring Class A Class A � Extract Method Refactoring Chained Clone � Extract Super Class Refactoring Method a11 Method a11 Method a12 Method a12 Method a1 Method a1 � Depending on the hierarchy relationship among D di th hi h l ti hi Java classes having chained clones, we provide appropriate refactoring for each chained clone. Method a21 Method a22 Method a2 � All chained clones in a chained clone set is in single class � Extract Method Refactoring is appropriate All methods can be merged into two new methods in the class A. � All chained clones in a chained clone set is in multiple (“Extract Method” Refactoring) classes that have common parent classes � Pull Up Method Refactoring is appropriate [1] M. Fowler: Refactoring: Improving the Design of Existing Code, Addison-Wesley, 1999. 11 12 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 2

Recommend


More recommend