Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 ARIES: Refactoring.

Slides:



Advertisements
Similar presentations
Written by: Dr. JJ Shepherd
Advertisements

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Modularization.
Reverse Engineering © SERG Code Cloning: Detection, Classification, and Refactoring.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Extracting Code.
A Tool Support to Merge Similar Methods with a Cohesion Metric COB ○ Masakazu Ioka 1, Norihiro Yoshida 2, Tomoo Masai 1,Yoshiki Higo 1, Katsuro Inoue 1.
13/07/2015Dr Andy Brooks1 Fyrirlestrar 9 & 10 CCFinder: A Tool to Detect Clones “I can just copy these lines. That is the safest thing to do. The code.
Refactoring Support Tool: Cancer Yoshiki Higo Osaka University.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Industrial Application.
Software Engineering Lab, Osaka University Code Clone Analysis and Its Application Katsuro Inoue Osaka University.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Debugging Support.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University ICSE 2003 Java.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Finding Similar.
Code Clone Analysis and Its Application
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University What Kinds of.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Refactoring.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University A Criterion for.
Department of Computer Science, Graduate School of Information Science and Technology, Osaka University DCCFinder: A Very- Large Scale Code Clone Analysis.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Investigation.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University A clone detection approach for a collection of similar.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University A Method to Detect License Inconsistencies for Large-
Mining and Analysis of Control Structure Variant Clones Guo Qiao.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Code-Clone Analysis.
2002/12/11PROFES20021 On software maintenance process improvement based on code clone analysis Yoshiki Higo* , Yasushi Ueda* , Toshihiro Kamiya** , Shinji.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University Detection and evolution analysis of code clones for.
CMCD: Count Matrix based Code Clone Detection Yang Yuan and Yao Guo Key Laboratory of High-Confidence Software Technologies (Ministry of Education) Peking.
1 Gemini: Maintenance Support Environment Based on Code Clone Analysis *Graduate School of Engineering Science, Osaka Univ. **PRESTO, Japan Science and.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Design and Implementation.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Applying Clone.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University Inoue Laboratory Eunjong Choi 1 Investigating Clone.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University How to extract.
Software Engineering Research Group, Graduate School of Engineering Science, Osaka University 1 Evaluation of a Business Application Framework Using Complexity.
Refactoring1 Improving the structure of existing code.
Refactoring Deciding what to make a superclass or interface is difficult. Some of these refactorings are helpful. Some research items include Inheritance.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Code-Clone Detection.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 1 Towards an Assessment of the Quality of Refactoring.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Assertion with.
1 CSC/ECE 517 Fall 2010 Lec. 3 Overview of Eclipse Lectures Lecture 2 “Lecture 0” Lecture 3 1.Overview 2.Installing and Running 3.Building and Running.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 1 Towards an Investigation of Opportunities for Refactoring.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Finding Code Clones.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University IWPSE 2003 Program.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Cage: A Keyword.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Code Clone Analysis.
1 Software Maintenance and Evolution CSSE 575: Session 3, Part 3 Dealing with Generalization Steve Chenoweth Office Phone: (812) Cell: (937)
1 Measuring Similarity of Large Software System Based on Source Code Correspondence Tetsuo Yamamoto*, Makoto Matsushita**, Toshihiro Kamiya***, Katsuro.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Classification.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Extracting Sequence.
Cross Language Clone Analysis Team 2 February 3, 2011.
What kind of and how clones are refactored? A case study of three OSS projects WRT2012 June 1, Eunjong Choi†, Norihiro Yoshida‡, Katsuro Inoue†
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 コードクローン解析に基づくリファクタリング支援.
Refactoring1 Improving the structure of existing code.
Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Towards a Collection of Refactoring Patterns Based.
Classes, Interfaces and Packages
1 Gemini: Code Clone Analysis Tool †Graduate School of Engineering Science, Osaka Univ., Japan ‡ Graduate School of Information Science and Technology,
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Aries: Refactoring.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University Detection of License Inconsistencies in Free and.
On Detection of Gapped Code Clones using Gap Locations Yasushi Ueda†, Toshihiro Kamiya‡, Shinji Kusumoto†, and Katsuro Inoue† †Graduate School of Information.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University A Metric-based Approach for Reconstructing Methods.
Estimating Code Size After a Complete Code-Clone Merge Buford Edwards III, Yuhao Wu, Makoto Matsushita, Katsuro Inoue 1 Graduate School of Information.
Yasuhiro Hayase†, Yu Kashima‡, Yuki Manabe‡, Katsuro Inoue‡
Module Road Map Refactoring Why Refactoring? Examples
Refactoring Support Based on Code Clone Analysis
A Pluggable Tool for Measuring Software Metrics from Source Code
○Yuichi Semura1, Norihiro Yoshida2, Eunjong Choi3, Katsuro Inoue1
Overview of Eclipse Lectures
Predicting Fault-Prone Modules Based on Metrics Transitions
Improving the structure of existing code
Refactoring Support Tool: Cancer
On Refactoring Support Based on Code Clone Dependency Relation
Dotri Quoc†, Kazuo Kobori†, Norihiro Yoshida
Presentation transcript:

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 ARIES: Refactoring Support Tool for Code Clone Yoshiki Higo 1, Toshihiro Kamiya 2, Shinji Kusumoto 1, Katsuro Inoue 1 1 Osaka University 2 National Institute of Advanced Industrial Science and Technology {y-higo, kamiya, kusumoto,

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 2 Contents Background Proposed Refactoring Support Method Step1, Step2, Step3 Metrics used in Step3 Refactoring Support Tool Aries Case Study Overview Filtering Conditions Evaluation Method Result Conclusion

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 3 Background What is code clone? a code fragment that has identical or similar fragments in the same or different files in a system introduced in the source program because of various reasons such as reusing code by `copy-and-paste’ makes software maintenance more difficult. copy-and-paste

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 4 Contents Background Proposed Refactoring Support Method Step1, Step2, Step3 Metrics used in Step3 Refactoring Support Tool Aries Case Study Overview Filtering Conditions Evaluation Method Result Conclusion

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 5 Our Refactoring Support Method for Code Clone We have proposed a refactoring support method for code clone We adopt three steps to get refactoring-oriented code clones quickly First Step: Run CCFinder to get token-based code clones Second Step: Extract structural parts from code clones detected by CCFinder Final Step: Characterize extracted code clones to predict how they can be refactored We have implemented our method as a tool Aries In this presentation, we explain about our method and report the result of a case study using Aries

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 6 Our Refactoring Support Method: First Step: CCFinder (Outline) CCFinder directly compares source code on token unit, and detects code clones Normalization of name space Replacement of names defined by user Removal of table initialization Consideration of module delimiter CCFinder can analyze the system of millions line scale in practical use time

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 7 Source files Lexical analysis Transformation Token sequence Match detection Transformed token sequence Clones on transformed sequence Formatting Clone pairs 1. static void foo() throws RESyntaxException { 2. String a[] = new String [] { "123,400", "abc", "orange 100" }; 3. org.apache.regexp.RE pat = new org.apache.regexp.RE("[0-9,]+"); 4. int sum = 0; 5. for (int i = 0; i < a.length; ++i) 6. if (pat.match(a[i])) 7. sum += Sample.parseNumber(pat.getParen(0)); 8. System.out.println("sum = " + sum); 9. } 10. static void goo(String [] a) throws RESyntaxException { 11. RE exp = new RE("[0-9,]+"); 12. int sum = 0; 13. for (int i = 0; i < a.length; ++i) 14. if (exp.match(a[i])) 15. sum += parseNumber(exp.getParen(0)); 16. System.out.println("sum = " + sum); 17. } Lexical analysis Transformation Token sequence Match detection Transformed token sequence Clones on transformed sequence Formatting Lexical analysis Transformation Token sequence Match detection Transformed token sequence Clones on transformed sequence Formatting 1. static void foo() throws RESyntaxException { 2. String a[] = new String [] { "123,400", "abc", "orange 100" }; 3. org.apache.regexp.RE pat = new org.apache.regexp.RE("[0-9,]+"); 4. int sum = 0; 5. for (int i = 0; i < a.length; ++i) 6. if (pat.match(a[i])) 7. sum += Sample.parseNumber(pat.getParen(0)); 8. System.out.println("sum = " + sum); 9. } 10. static void goo(String [] a) throws RESyntaxException { 11. RE exp = new RE("[0-9,]+"); 12. int sum = 0; 13. for (int i = 0; i < a.length; ++i) 14. if (exp.match(a[i])) 15. sum += parseNumber(exp.getParen(0)); 16. System.out.println("sum = " + sum); 17. } Lexical analysis Transformation Token sequence Match detection Transformed token sequence Clones on transformed sequence Formatting Our Refactoring Support Method: First Step: CCFinder (Clone Detection Process)

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 8 Definitions: Clone Pair and Clone Set Clone Pair: a pair of identical or similar fragments Clone Set: a set of identical or similar fragments CCFinder detects code clones as clone pairs After detection process, clone pairs are transformed into clone sets C1 C5 C4 C3 C2 Clone PairClone Set (C1, C4){C1, C4, C5} (C1, C5){C2, C3} (C2, C3) (C4, C5)

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 9 Our Refactoring Support Method: Second Step: Extract Structural Code Clones Structural code clones are regarded as the target of refactoring Extract structural parts as structural code clones from the detected clone sets What is structural code clone ? example: Java language Declaration: class declaration, interface declaration Method: method body, constructor, static initializer Statement: do, for, if, switch, synchronized, try, while

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University : reset(); 610: grammar = g; 611: // Lookup make-switch threshold in the grammar generic options 612: if (grammar.hasOption("codeGenMakeSwitchThreshold")) { 613: try { 614: makeSwitchThreshold = grammar.getIntegerOption("codeGenMakeSwitchThreshold"); 615: //System.out.println("setting codeGenMakeSwitchThreshold to " + makeSwitchThreshold); 616: } catch (NumberFormatException e) { 617: tool.error( 618: "option 'codeGenMakeSwitchThreshold' must be an integer", 619: grammar.getClassName(), 620: grammar.getOption("codeGenMakeSwitchThreshold").getLine() 621: ); 622: } 623: } 624: 625: // Lookup bitset-test threshold in the grammar generic options 626: if (grammar.hasOption("codeGenBitsetTestThreshold")) { 627: try { 628: bitsetTestThreshold = grammar.getIntegerOption("codeGenBitsetTestThreshold"); 623: } 624: 625: // Lookup bitset-test threshold in the grammar generic options 626: if (grammar.hasOption("codeGenBitsetTestThreshold")) { 627: try { 628: bitsetTestThreshold = grammar.getIntegerOption("codeGenBitsetTestThreshold"); 629: //System.out.println("setting codeGenBitsetTestThreshold to " + bitsetTestThreshold); 630: } catch (NumberFormatException e) { 631: tool.error( 632: "option 'codeGenBitsetTestThreshold' must be an integer", 633: grammar.getClassName(), 634: grammar.getOption("codeGenBitsetTestThreshold").getLine() 635: ); 636: } 637: } 638: 639: // Lookup debug code-gen in the grammar generic options 640: if (grammar.hasOption("codeGenDebug")) { 641: Token t = grammar.getOption("codeGenDebug"); 642: if (t.getText().equals("true")) { fragment 1fragment 2 Code clones which CCFinder detects Code clones which our method detects

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University : if ( inputState.guessing==0 ) { 1008: buf.append(a.getText()); 1009: } 1010: { 1011: _loop144: 1012: do { 1013: if ((LA(1)==WILDCARD)) { 1014: match(WILDCARD); 1015: a=id(); 1016: if ( inputState.guessing==0 ) { 1017: buf.append('.'); buf.append(a.getText()); 1018: } 1019: } 1527: if ( inputState.guessing==0 ) { 1528: t=a.getText(); 1529: } 1530: { 1531: _loop84: 1532: do { 1533: if ((LA(1)==COMMA)) { 1534: match(COMMA); 1535: id(); 1536: if ( inputState.guessing==0 ) { 1537: t+=","+b.getText(); 1538: } 1539: } Code clones which CCFinder detects

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 12 Our Refactoring Support Method: Final Step: Characterize Extracted Code Clones The following refactoring patterns[1][2] can be applied to remove clone sets including structural code clones Extract Class, Extract Method, Extract Super Class, Form Template Method, Move Method, Parameterize Method, Pull Up Constructor, Pull Up Method, For each clone set, our method determines which refactoring pattern is applicable by using several metrics. [1]: M. Fowler: Refactoring: Improving the Design of Existing Code, Addison-Wesley, [2]:

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 13 Metrics(1): Coupling Metrics for Clone Set NRV, NSV NRV(S): represents the average number of externally defined variables referred in the fragment of a clone set S NSV(S): represents the average number of externally defined variables assigned to in the fragment of a clone set S Definition Clone set S includes fragment f 1, f 2, ・・・, f n s i is the number of externally defined variable which fragment f i refers t i is the number of externally defined variable which fragment f i assigns int a, b, c; … if( … ){ … ; … = b + c; a = … ; … ; } … assignment reference Fragment f 1 example : ・ Clone set S includes fragments f 1 and f 2. ・ In fragment f 1, externally defined variable b and c are referred and a is assigned to. ・ Fragment f 2 is same as f 1. then , NRV(S) = ( ) / 2 = 2 NSV(S) = ( ) / 2 = 1 int a, b, c; … if( … ){ … ; … = b + c; a = … ; … ; } … Fragment f 2 reference assignment

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 14 Metrics ( 2 ): Inheritance Metric for Clone Set DCH DCH(S): represents the position and distance between each fragment of a clone set S Definition Clone set S includes fragment f 1, f 2, ・・・, f n Fragment f i exists in class C i Class C p is a class which locates lowest position in C 1, C 2, ・・・, C n on class hierarchy If no common parent class of C 1 , C 2 ,・・・, C n exists, the value of DCH(S) is -1 This metric is measured for only the class hierarchy where target software exists. example 1: ・ Clone set S includes fragments f 1 and f 2. ・ If all fragments of clone set S are included in a same class, then , DCH(S) = 0 class A fragment f 1 fragment f 2 class A class B class C fragment f 1 fragment f 2 example 2 : ・ Clone set S includes fragments f 1 and f 2. ・ If all fragments of clone set S are included in a class and its direct child classes, then , DCH(S) = 1 fragment f 1 fragment f 2 class A class B example 3 : ・ Clone set S includes fragments f 1 and f 2. ・ If all classes which include f 1 and f 2 don ’ t have common parent class, then , DCH(S) = ∞

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 15 Aries: Refactoring Support Tool Overview Target: Java programs Runtime environment: JDK1.4 or above Implementation Analysis component: Java 32,000 Lines CCFinder is used as code clone detection component JavaCC is used to construct syntax and semantic analysis component GUI component: Java14,000 Lines User can specify target clone sets through GUI operations.

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 16 Contents Background Proposed Refactoring Support Method Step1, Step2, Step3 Metrics used in Step3 Refactoring Support Tool Aries Case Study Overview Filtering Conditions Evaluation Method Result Conclusion

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 17 Case Study: Overview Business application developed by a software company in Japan Size LOC: 70,000 Number of classes: 309 Process of case study Step1: Extract clone set which can be refactored using the following refactoring patterns Extract Super Class Move Method Extract Method Step2: Qualitatively evaluate the results of the refactorings by a developer from the viewpoint of size, design, cohesion, coupling, understandability, and reusability

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 18 Case Study: Filtering Conditions(1/3) Conditions for “Extract Super Class” The target is Class-Unit clone sets Cloned Classes have no parent Department Employee getTotalAnnualCost() getName() getHeadCount() getAnnualCost() getName() getId() Before Refactoring Employee getTotalAnnualCost() getHeadCount() Department getTotalAnnualCost() getHeadCount() Party getAnnualCost() getName() After Refactoring Similar classes

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 19 Case Study: Filtering Conditions(1/3) Conditions for “Move Method” The target is Method-Body-Unit clone sets Cloned methods use no other resource of its class ClassA Before Refactoring ClassB ClassC ClassD clonedMethod() ClassA After Refactoring ClassB ClassC ClassD UtilityClass clonedMethod()

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 20 Case Study: Filtering Conditions(1/3) Conditions for “Extract Method” The target is Statement-Unit clone sets such as “if”, “while”, “for” … Cloned statements assign any value to 1 or no externally defined variable All statements of a clone set are in a same class void methodA(int i){ methodZ(); System.out.println( “ name: ” + name); System.out.println( “ amount: ” + i); } void methodB(int i){ methodY(); System.out.println( “ name: ” + name); System.out.println( “ amount: ” + i); } void methodA(int i){ methodZ(); methodC(i); } void methodB(int i){ methodY(); methodC(i); } void methodC(int i){ System.out.println( “ name: ” + name); System.out.println( “ amount: ” + i); } Before RefactoringAfter Refactoring

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 21 Case Study: Result of Filtering Number of detected clone set Declaration Unit: 4 Method Unit: 13 Statement Unit: 49 Number of filtered clone set Extract Super Class: 4 Move Method: 5 Extract Method: 12

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 22 Case Study: Evaluation Method(1/3) A developer of the target system evaluated refactorings of filtered clone sets from the following viewpoints About status of clones (He judged each following term of the status on a scale of (a) or (b)) size of module design of software cohesion of class coupling among classes (a) deteriorating, (b) making no impact

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 23 Case Study: Evaluation Method(2/3) The continuation About effectiveness of refactorings (He judged each following term of the effectiveness on a scale from (a) to (d) ) size design cohesion coupling understandability reusability (a) improving , (b) preventing problems for the future , (c) having no impact , (d) deteriorating

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 24 Case Study: Evaluation Method(3/3) The continuation About costs of refactorings (He judges two terms of the cost on a scale from (a) to (c)) modifying source code testing for regression (a) very easy, (b) a little troublesome , (c) complicated Comprehensive Evaluation ( He judged the comprehensive evaluation on a scale from (a) to (d)) This clone set … (a) must be refactored as soon as possible (b) should be refactored for the future (c) is no matter about refactoring (d) should not be refactored

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 25 The status of “Declaration-Unit” clones All clone sets deteriorate size and design All clone sets have no impact on cohesion, and coupling Case Study: The Result - Extract Super Class ( 1/4 ) (a)(b)Total Size404 Design404 Cohesion044 Coupling044 (a)Deteriorating (b)Making no Impact

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 26 The effectiveness of “Declaration-Unit” refactorings Refactorings of all clone sets are effective in terms of size, design, understandability, and reusability Refactorings of all clone sets have no impact in terms of cohesion, and coupling Case Study: The Result - Extract Super Class ( 2/4 ) (a)(b)(c)(d)Total Size22004 Design22004 Cohesion00404 Coupling00404 Understandabilit y Reusability13004 (a)Improving (b)Preventing problems for the future (c)Having no impact (d)Deteriorating

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 27 The cost of “Declaration-Unit” refactorings Modifying requires a little trouble Testing becomes complicated in some cases The comprehensive evaluation of “Declaration-Unit” refactoring All clone sets must or should be refactored Case Study: The Result - Extract Super Class ( 3/4 ) (a)(b)(c)Total Modifying1304 Testing1124 (a)(b)(c)(d)Total Refactoring … (a)Very Easy (b)A little Troublesome (c)Complicated (a)Must be refactored (b)Should be refactored (c)No matter (d)Shouldn ’ t be refactored

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 28 Case Study: The Result - Extract Super Class ( 4/4 ) AcceptHeadCheckerSakubanHeadChecker doStartTag() doAfterBody() doEndTag() doStartTag() doAfterBody() doEndTag() New Class doAfterBody() doEndTag() AcceptHeadCheckerSakubanHeadChecker doStartTag() Before RefactoringAfter Refactoring Methods “DoAfterBody” and “DoEndTag” are exactly identical respectively Methods “DoStartTag” provides different functions

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 29 The status of “Method-Unit” clones All clone sets deteriorate size and design Most of them(80%) deteriorate cohesion All clone sets have no impact on coupling Case Study: The Result - Move Method ( 1/4 ) (a)(b)Total Size505 Design505 Cohesion415 Coupling055 (a)Deteriorating (b)Making no Impact

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 30 The effectiveness of “Method-Unit” refactorings Refactorings of all clone sets are effective in terms of size, design, cohesion, understandability, and reusability Refactorings of all clone sets have no impact on coupling Case Study: The Result - Move Method ( 2/4 ) (a)(b)(c)(d)Total Size50005 Design50005 Cohesion50005 Coupling00505 Understandabilit y Reusability41005 (a)Improving (b)Preventing problems for the future (c)Having no impact (d)Deteriorating

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 31 The cost of “Method-Unit” refactorings Both modifying and testing are very easy The comprehensive evaluation of “Method-Unit” refactorings All clone sets must or should be refactored Case Study: The Result - Move Method ( 3/4 ) (a)(b)(c)Total Modifyin g 5005 Testing5005 (a)(b)(c )(d)Total Refactoring …41005 (a)Very Easy (b)A little Troublesome (c)Complicated (a)Must be refactored (b)Should be refactored (c)No matter (d)Shouldn ’ t be refactored

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 32 Case Study: The Result - Move Method ( 4/4 ) The following method exist in 9 classes This method converts ResultData to HashMap This method uses no other fields or methods of its class Moving to other class is very easy The developer judged that this refactoring is effective private HashMap convertToMap(ResultData rd){ String[] names = rd.getNames(); HashMap map = new HashMap(); for( int i = names.length ; i++ ){ map.put([i], rd.getObject(names[i])); } return map; }

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 33 The status of “Statement-Unit” clones Part of clone sets deteriorates size and design All clone sets have no impact on cohesion, and coupling Case Study: The Result - Extract Method ( 1/4 ) (a)(b)Total Size21012 Design21012 Cohesion012 Coupling012 (a)Deteriorating (b)Making no Impact

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 34 The effectiveness of “Statement-Unit” refactorings The effectiveness of refactorings is divisive in terms of size, design, understandability, and reusability Refactorings of all clone set have no impact on cohesion, and coupling Case Study: The Result - Extract Method ( 2/4 ) (a)(b)(c)(d)Total Size Design Cohesion00120 Coupling00120 Understandabilit y Reusability (a)Improving (b)Preventing problems for the future (c)Having no impact (d)Deteriorating

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 35 The cost of “Statement-Unit” refactorings Almost half of clone sets require a lot of cost on both modifying and testing The comprehensive evaluation of “Statement-Unit” refactorings Almost half of clone sets shouldn’t be refactored Case Study: The Result - Extract Method ( 3/4 ) (a)(b)(c)Total Modifyin g Testing26412 (a)(b)(c)(d)Total Refactoring … (a)Very Easy (b)A little Troublesome (c)Complicated (a)Must be refactored (b)Should be refactored (c)No matter (d)Shouldn ’ t be refactored

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 36 Case Study: The Result - Extract Method ( 4/4 ) The following if-statement appeared 5 times in a class Red variables mean that they are defined outside this if-statement They must be added to the argument of the extracted method. This statement can be extracted as a new method in the same class, but … The argument of the new method become long. Extracting 5 times requires a lot of cost. if( vomrgpersonSyuningishi.getName() != null && !vomrgpersonSyuningishi.getName().equals( “” )) { checkOwnSettlement(vomrgpersonSyuningishi.getShimeiNo(), vomrgpersonSyuningishi.getName(), vomanager, voprojectinfo, vodocumentinfo, vomrgpersonSyunigishi.getBusyomei()); }

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 37 Some “Statement-Unit” clones were judged as not suited to be refactored Extracting manually a part of a method is complicated Making the filtering conditions stricter Helping modification working Some clone sets depend on the framework used in the system The following table represents the ratio of refactorings judged as effective ((a) improving, or (b) preventing problems for the future) Case Study: Discussions Extract Super Class Move Method Extract Method Size4/4 (100%)5/5 (100%)5/12 ( 42%) Design4/4 (100%)5/5 (100%)3/12 ( 25%) Cohesion0/4 ( 0%)5/5 (100%)0/12 ( 0%) Coupling0/4 ( 0%)0/5 ( 0%)0/12 ( 0%) Understandability4/4 (100%)5/5 (100%)4/12 ( 33%) Reusability4/4 (100%)5/5 (100%)4/12 ( 33%) “Extract Super Class” and “Move Method” refactorings are effective Those clone sets deteriorate some software qualities Refactorings of them can improve qualities They don’t require much cost

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 38 Contents Background Proposed Refactoring Support Method Step1, Step2, Step3 Metrics used in Step3 Refactoring Support Tool Aries Case Study Overview Filtering Conditions Evaluation Method Result Conclusion & Future Works

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 39 Conclusion & Future works We have proposed refactoring support method implemented a refactoring support tool, Aries conducted a case study to a business application “Declaration-Unit” and “Method-Unit” refactorings are effective Some “Statement-Unit” clones are not appropriate to be refactored As future works, we are going to evaluate refactoring effectiveness quantitatively add an effectiveness measurement function to Aries for comprehensive supporting refactoring of code clones

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

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 41 Code clone detection for refactoring: Related Works Detect similar sub-graphs as clone on program dependency graph [1]. High accuracy: This approach finds out data-dependence and control dependence in source codes. High time complexity: It takes O(n 2 ) time to construct program dependency graph. Detect similar methods and functions as clone using metrics [2]. Low accuracy: if the size of target method or function is small, the values of metric make no difference. detection unit restriction: only method and function unit clone can be detected. [1] R. Komondoor and S. Horwitz, “ Using slicing to identify duplication in source code ”, In Proc. of the 8th International Symposium on Static Analysis, Paris, France, July 16-18, [2] Magdalena Balazinska, Ettore Merlo, Michel Dagenais, Bruno Lague, and Lostas Kontogiannis, “Advanced Clone-Analysis to Support Object-Oriented System Refactoring”, WCRE 2000, pp

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 42 Properties Size: means the number of lines or token of modules Design: means the structure of hierarchy of classes or encapsulation of classes Cohesion: means the responsibility of classes. If a classes provide no or various functions, the cohesion of the class becomes wrong (low) Coupling: means usage of fields or method of other classes. If fields or methods are defined in an inappropriate class, the coupling becomes wrong (high)