Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Recommending Source Code Locations for System Specific Transformations (SANER 2017)

gustavojss
February 23, 2017

Recommending Source Code Locations for System Specific Transformations (SANER 2017)

From time to time, developers perform sequences of code transformations in a systematic and repetitive way. This may happen, for example, when introducing a design pattern in a legacy system: similar classes have to be introduced, containing similar methods that are called in a similar way. Automation of these sequences of transformations has been proposed in the literature to avoid errors due to their repetitive nature. However, developers still need support to identify all the relevant code locations that are candidate for transformation. Past research showed that these kinds of transformation can lag for years with forgotten instances popping out from time to time as other evolutions bring them into light. In this paper, we evaluate three distinct code search approaches (“structural”, based on Information Retrieval, and AST based algorithm) to find code locations that would require similar transformations. We validate the resulting candidate locations from these approaches on real cases identified previously in literature. The results show that looking for code with similar roles, e.g., classes in the same hierarchy, provides interesting results with an average recall of 87% and in some cases the precision up to 70%.

gustavojss

February 23, 2017
Tweet

More Decks by gustavojss

Other Decks in Programming

Transcript

  1. Recommending Source Code Locations for System Specific Transformations Gustavo Santos,

    Klérisson Paixão, Nicolas Anquetil, Anne Etien, Marcelo Maia, and Stéphane Ducasse
  2. Motivation Repetitive sequences of code transformations JHotDraw 7.4.1 → 7.5.1

    2 { { add interface NamedColorSpace to HSBColorSpace add method getName() in HSBColorSpace add return “HSB” in getName() /* implement Singleton design pattern in HSBColorSpace */ add interface NamedColorSpace to CIELCHabColorSpace add method getName() in CIELCHabColorSpace add return “CIE 1976 L*CHa*b*” in getName() /* implement Singleton design pattern in CIELCHabColorSpace */ add interface NamedColorSpace to HSBColorSpace add method getName() in HSBColorSpace add return “HSB” in getName() /* implement Singleton design pattern in HSBColorSpace */ add interface NamedColorSpace to CIELCHabColorSpace add method getName() in CIELCHabColorSpace add return “CIE 1976 L*CHa*b*” in getName() /* implement Singleton design pattern in CIELCHabColorSpace */ Identical transformations Similar entities Santos et. al., System Specific, Source Code Transformations. ICSME 2015
  3. Systematic Code Transformation Sequence of small code transformations applied to

    similar code entities 3 Systematic Code Transformation Refactoring Repetitive (occasional) Repetitive (daily) System-specific System- and language-independent Several entities at each time Couple of classes / methods Not fully supported by refactorings Tool support in most IDEs
  4. 4 source code changed code entities macro candidate locations Santos

    et. al., Recording and Replaying System Specific, Source Code Transformations. SCAM 2015
  5. Existing Approaches One (or more) code examples Specify a query,

    e.g., all classes with a given condition Refactoring opportunities, e.g., where to apply Extract Class Frequent bug fixes 5
  6. (2/3) AST-based Approach 8 public CIELABColorSpace() { super(ColorSpace.TYPE_Lab, 3); Xw

    = D65[0]; Yw = D65[1]; Zw = D65[2]; } public HSBColorSpace() { super(ColorSpace.TYPE_HSV, 3); } public HSBColorSpace() { super(ColorSpace.TYPE_HSV, 3); } public CIELABColorSpace() { super(ColorSpace.TYPE_Lab, 3); Xw = D65[0]; Yw = D65[1]; Zw = D65[2]; } 4 nodes similar
  7. (3/3) IR-based Approach 9 public HSBColorSpace() { super(ColorSpace.TYPE_HSV, 3); }

    satur color count system common green light blue base primary hsv public CIELABColorSpace() { super(ColorSpace.TYPE_Lab, 3); Xw = D65[0]; Yw = D65[1]; Zw = D65[2]; } clamp outside gamut ciexyz color system handl value cosine similarity = 0.2
  8. Evaluation Examples of systematic transformations in previous work Macros are

    also available from previous work Gold standard, i.e., correct recommendations, is also known Randomly select one (or more) code example 10
  9. Dataset 11 Occurrences Number of Transformations PetitDelphi 21 2 PetitSQL

    I 6 3 PetitSQL II 98 3 PackageManager I 50 5 PackageManager II 19 3 PackageManager III 64 2 PackageManager IV 7 6 Pillar 99 4 MooseQuery I 16 1 MooseQuery II 8 4 Average 36 3
  10. Code Search approaches 12 Precision (%) Structural AST-based IR-based PetitDelphi

    12 4 2 PetitSQL I 24 27 16 PetitSQL II 40 32 94 PackageManager I 100 74 92 PackageManager II 100 100 54 PackageManager III 100 100 87 PackageManager IV 66 66 5 Pillar 19 77 75 MooseQuery I 41 34 19 MooseQuery II 12 2 16 Average 51 51 46 F-measure 0.64 0.48 0.43 Only looking at similar locations, Structural approach gives better results.
  11. Using the macro 13 Precision (%) Structural + Macro AST-based


    + Macro IR-bases
 + Macro PetitDelphi 12 4 2 PetitSQL I 85 85 57 PetitSQL II 40 32 94 PackageManager I 100 74 92 PackageManager II 100 100 54 PackageManager III 100 100 87 PackageManager IV 66 66 5 Pillar 93 93 93 MooseQuery I 66 48 31 MooseQuery II 40 10 33 Average 70 60 54 Filtering results with the macro improved precision in four cases.
  12. Conclusion We evaluated three approaches to find transformation opportunities Structural

    approach performed best, with 51% precision. Using the macro to validate the recommendations improved precision to 70% 14
  13. Provocative Question When performing complex and repetitive transformations,
 what would

    practitioners prefer to apply them consistently: • a recommendation system to find transformation opportunities • or a DSL powerful enough to express what locations should be transformed? 15 Thank you! http://gustavojss.github.io/