1 / 18

Refactoring Support Tool: Cancer

Refactoring Support Tool: Cancer. Yoshiki Higo Osaka University. Gemini & Cancer. Gemini shows all code clones detected by CCFinder. gives user panoramic views of code clones in source code. has several quantitative information of code clones of each file and clone class. Cancer

shada
Télécharger la présentation

Refactoring Support Tool: Cancer

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Refactoring Support Tool:Cancer Yoshiki Higo Osaka University

  2. Gemini & Cancer • Gemini • shows all code clones detected by CCFinder. • gives user panoramic views of code clones in source code. • has several quantitative information of code clones of each file and clone class. • Cancer • extracts refactoring-oriented-code clones from ones detected by CCFinder. • appends several metric values to extracted code clones. • enables user to know how to remove code clones if certain degree of its metric conditions is satisfied.

  3. Declaration unit code clone • class declaration、interface declaration • Method unit code clone • method body、constructor、static initializer • Statement unit code clone • do 、for 、if 、switch 、synchronized 、try 、while Code clones in Cancer • All code clones ( which are extracted from ones detected by CCFinder) correspond to structural blocks of programming language. • Currently, Cancer can apply only Java language.

  4. Metrics in Cancer(1/3) • Cancer characterizes extracted code clones using 6 metrics. • Using these metrics, we can get how to remove them. • 6 metrics are RVK,RVN,DCH,LEN,POP,DFL

  5. Class A{ ・・・ void foo( ・・・ ){ ・・・ } ・・・ void bar( ・・・ ){ ・・・ } ・・・ } int a; MyClass myClass = new MyClass(); ・・・ for( int i = a ; i < 10 ; i++ ){ int c = a + 1; myClass.set(c); } ・・・ Class A{ ・・・ } Class B extends A{ ・・・ void foo( ・・・ ){ ・・・ } ・・・ } Class C extends A{ ・・・ void bar( ・・・ ){ ・・・ } ・・・ } code clone code clone The value of DCH : 0 RVK variable The value of RVK : 2 The value of RVN : 2 + 1 = 3 code clone The value of DCH : 1 Metrics in Cancer(2/3) • Variables which are used in code clone, but defined outside. • RVK : the number of such variables. • RVN : the sum of used count of such variables. • Relation of code clone on class hierarchy • DCH : the degree of dispersion on class hierarchy DCH takes into account only class hierarchy of target software (don’t include class hierarchy of library).

  6. new sub routine caller statements Metrics in Cancer(3/3) • LEN: the average of length of code clones in a clone class • POP: the number of code clones in a clone class • DFL: Estimation of how many tokens would be removed from source files when all code clones of a clone class are replaced with caller statements of a new identical routine

  7. Removal of Code clone using Refactoring Pattern • We use Refactoring Pattern[1] for removal of code clones with 6 metrics • Following patterns are applicable. • Extract Method • Pull Up Method [1] M. Fowler: Refactoring: Improving the Design of Existing Code, Addison-Wesley, 1999.

  8. Target Unit : Method Unit, Statement Unit • DCH == 0 • RVK <= 1 int i; ・・・ ・・・ for( int j = 0 ; j < i ; j++ ){ ・・・ } ・・・ int i; ・・・ ・・・ i = newMethod(i); ・・・ int newMethod(int a){ for( int j = 0 ; j < a ; j++ ){ ・・・ } return a; } ・・・ The value of metrics for “Extract Method”

  9. Target Unit : Method Unit • DCH >= 1 The value of metrics for “Pull up Method”

  10. ShapShot of Cancer Metric Graph Clone class list clone category selection Panel

  11. Specifying code clones • User can specify code clones using Metric Graph and Clone Category Selection Panel • Metrics Graph : Specifying based on metric values • Clone Category Selection Panel : Specifying based on unit of code clone • Clone class list shows only specified clone classes

  12. LEN POP DFL RVK RVN DCH Specifying based on metrics values

  13. Method Unit While Unit LEN POP DFL RVK RVN DCH Specifying based on unit of code clone Method While ・・・・・・・・・・・・・・ ・・・・・・・・・・・・・

  14. Case study • Target software : Ant 1.5.4, which is an open source java software. • LOC : about 15k • The result • Using “Pull up Method”, 2 clone classes are removed. • Using “Extract Method”, 1 clone class is removed

  15. Clone Pair Clone Class Code Clone • Code clone is a code fragment in source files that is identical or similar to another • Code clone is one of factors that make software maintenance more difficult. • If some faults are found in a code clone, it is necessary to consider pros and cons of modification in its all code clones.

  16. Example Value of RVK, RVN • Variables, “a” and “b” which are used in code clone, but defined outside, are used 2 and 3 times. • RVK : 1 + 1 = 2 • RVN : 2 + 3 = 5

  17. Example values of DCH • If all code fragments in a clone class are in same class, • DCH : 0 • If all code fragments in a clone class are in a certain class and its child classes, • DCH : 1 • If classes which include code fragments of a certain clone class don’t have common parent class, • DCH : -1

More Related