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

Recording and Replaying System Specific, Source Code Transformations (SCAM 2015)

gustavojss
September 28, 2015

Recording and Replaying System Specific, Source Code Transformations (SCAM 2015)

During its lifetime, a software system is under continuous maintenance to remain useful. We found evidences that developers sometimes perform sequences of code changes in a systematic way. These sequences consist of small code changes (e.g., create a class, then extract a method to this class), which are applied to groups of related code entities (e.g., some of the methods of a class). This paper presents the design and proof-of-concept implementation of a tool called MacroRecorder. This tool records a sequence of code changes, then it allows the developer to generalize this sequence in order to apply it in other code locations. In this paper, we discuss MacroRecorder's approach that is independent of both development and transformation tools. The evaluation is based on previous work on repetitive code changes related to rearchitecting. MacroRecorder was able to replay 92% of the examples, which consisted in up to seven code entities modified up to 66 times. The generation of a customizable, large-scale transformation operator has the potential to efficiently assist code maintenance.

Presented at SCAM '15

gustavojss

September 28, 2015
Tweet

More Decks by gustavojss

Other Decks in Research

Transcript

  1. Recording and Replaying System Specific, Source Code Transformations Gustavo Santos,

    Anne Etien, Nicolas Anquetil, Stéphane Ducasse, and Marco Tulio Valente
  2. Systematic Code Transformation 2 PackageManager 0.58 → 0.59 GreasePharo30CoreSpec 


    
 SeasideCanvas20CoreSpec - platform - package addPlatformRequirement: #’pharo’. - package addProvision: #’Grease-Core-Platform’ + platformRequirements + ^ #( #’pharo’ ) + provisions + ^ #( #’Grease-Core-Platform’ ) Applied 19 times - platform - package addPlatformRequirement: #’pharo2.x’. - package addProvision: #’Seaside-Canvas-Platform’ + platformRequirements + ^ #( #’pharo2.x’ ) + provisions + ^ #( #’Seaside-Canvas-Platform’ )
  3. What if… Manually perform the changes once Record these changes

    Generalize the recorded changes Replay the changes in other locations 5
  4. X Illustrating Example - Replay with the selected method Replay

    Inspect the changes before applying, then execute
  5. Evaluation Transformation patterns found in Smalltalk systems [San2015] 8 Occurrences

    Number of Operators Number of Parameters PetitDelphi 21 2 3 PetitSQL 6 3 6 PackageManager I 66 2 7 PackageManager II 19 3 5 PackageManager III 64 2 4 PackageManager IV 7 3 5 Average 30 3 5
  6. Evaluation We have the code before and after the changes

    Record one random occurrence with MacroRecorder Configure until we can apply the pattern a second time Replay the pattern in all the occurrences Compare the resulting code with the developer’s manual edition 9
  7. Complexity How many parameters do we need to configure in

    MacroRecorder? 10 Number of Parameters Configured Parameters PetitDelphi 3 1 PetitSQL 6 1 PackageManager I 7 2 PackageManager II 5 2 PackageManager III 4 1 PackageManager IV 5 2 We configured up to two parameters to apply the transformation pattern a second time
  8. Complexity X | packageName versionName | packageName := (( @class1

    lookupSelector: @method1 ) literals select: #isString ) detect: #isByteString. versionName := @class1 new version. '^ { #', packageName surroundedBySingleQuotes, ' -> #(', ('=', versionName) surroundedBySingleQuotes, ') }'
  9. Coverage In a new code location, can MacroRecorder perform the

    operators successfully? 11 Occurrences Matched Occurrences PetitDelphi 21 21 PetitSQL 6 6 PackageManager I 66 50 PackageManager II 19 14 PackageManager III 64 64 PackageManager IV 7 7 MacroRecorder covers 92% of new occurrences
  10. Recorded Change (in SeasideCoreSpec) 
 Automatic Replay (in SeasideEmailSpec) Coverage

    12 dependencies - ( package addDependency: ‘GreaseCore’ ) - addVersionConstraint: package version; - yourself dependencies + ^ { #’GreaseCore’ -> #(‘=1.1.5’) } dependencies - ( package addDependency: ‘SeasideCore’ ) - addVersionConstraint: package version; - yourself. ( package addDependency: ‘SeasideEmail’ ) addVersionConstraint: package version; yourself dependencies + ^ { #’SeasideCore’ -> #(‘=1.1.5’) }. ( package addDependency: ‘SeasideEmail’ ) addVersionConstraint: package version; yourself
  11. Accuracy Is the code modified by MacroRecorder equivalent to the

    developer’s manual edition? 13 76% of the occurrences are correct according to manual edition Occurrences Correct Occurrences PetitDelphi 21 21 PetitSQL 6 4 PackageManager I 66 11 PackageManager II 19 14 PackageManager III 64 64 PackageManager IV 7 7
  12. Similarity Is the code modified by MacroRecorder similar (in terms

    of AST nodes) to the developer’s manual edition? 14 79% of the AST nodes in the resulting code is similar to the developer’s manual edition Similarity (%) PetitDelphi 100 PetitSQL 85 PackageManager I 20 PackageManager II 100 PackageManager III 100 PackageManager IV 68
  13. Similarity 15 Manual Edition Automatic Transformation dependencies solver := Solver

    new add: repository. dependency := Dependency new package: package - . dependencies solver := Solver new add: repository. dependency := Dependency new package: package + ; version: ( Version with: ‘3.1’ ). dependencies solver := Solver new add: repository. - dependency := Dependency new - package: package - . dependencies + dependency := Dependency new + package: package + ; version: ( Version with: ‘3.1’ ). solver := Solver new add: repository.
  14. Conclusions Developers sometimes perform changes systematically Semi-automatic approach to compose

    and automatically apply source code changes MacroRecorder performed 92% of the examples. 76% of the automatic transformations are correct. The resulting code is 79% similar to manual edition. 16