Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

Transformation-based Refactorings: a First Analysis

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Prochain SlideShare
Lecture: Refactoring
Lecture: Refactoring
Chargement dans…3
×

Consultez-les par la suite

1 sur 35 Publicité

Plus De Contenu Connexe

Similaire à Transformation-based Refactorings: a First Analysis (20)

Plus par ESUG (20)

Publicité

Plus récents (20)

Transformation-based Refactorings: a First Analysis

  1. 1. N. Anquetil, M. Campero, S. Ducasse, J.P. Sandoval and P. Tesone Transformation-based Refactorings: a First Analysis International Workshop on Smalltalk Technologies
  2. 2. • Vocabulary • About the need of transformations • Research questions • Why RB engine? • Analyses and results Outline
  3. 3. • Refactoring: behavior preserving modi fi cation of the source code. • Transformation: behavior agnostic modi fi cation of the source code. • Pre-condition: a condition to hold before applying a refactoring • Atomic refactoring: A refactoring that is not implemented using some other refactorings • Composite refactoring: Not Atomic. • Elementary operation: A local modi fi cation of a program Vocabulary
  4. 4. • Vocabulary • About the need of transformations • Research questions • Why RB engine? • Analyses and results Outline
  5. 5. foo self x x doing something y doing something else bar t x Replace Call x by y foo self y x doing something y doing something else bar t y
  6. 6. This is not a refactoring because there is no warrantee that after the application behavior stays the same Replace Call Analysis
  7. 7. • Cannot easily be expressed with Rename Method Refactoring • Now the implementation is close to Rename Method • Look for all the senders • Replace all the senders with the target method Replace Call Analysis
  8. 8. • Developers are often left alone and do it manually • There is a need for transformations as well as refactorings Need for transformation too
  9. 9. • Could both refactorings and transformations share their code modi fi cation logic? • Could we decouple code transformations from refactorings to be able to reuse them when behavior preservation is not a concern? • Could we compose refactorings from such code transformations? Goal of the study
  10. 10. • Should we turn elementary operations into transformations? • At which cost complex refactorings be expressed out of simpler ones? Correlated questions
  11. 11. • An analysis of the original implementation of Refactorings. • The identi fi cation of di ff erent kinds of pre-conditions • Understanding program modi fi cation API • Identify atomic refactorings • The identi fi cation of missed reuse opportunities in current refactorings implementation • Path for the real work Contributions
  12. 12. • Seminal work • Documented in PhD of D. Roberts • Available and fully working • Nice architecture (compared to mainstream engines) • preview • support o ff line code Why RB engine? Refactorings RBMethod RBNamespace RBEntity RBAbstractClass RBPackage RBMetaclass RBClass Changes AST ParseTreeRewriter Condition Program Model
  13. 13. • A refactoring reason on a program model • Check preconditions on such a program model • Produces changes that can be previewed • Then actual modi fi cations are done The architectural elements Applying a refactoring Refactorings RBMethod RBNamespace RBEntity RBAbstractClass RBPackage RBMetaclass RBClass Changes AST ParseTreeRewriter Condition Program Model
  14. 14. • Vocabulary • About the need of transformations • Research questions • Why RB engine? • Analyses and results Outline
  15. 15. • None • Applicability check • Break check • Complex ones 4 Families Precondition Analysis
  16. 16. Looks like there were added by developers not following the design Should really be revisited Precondition: None
  17. 17. Precondition: None
  18. 18. Veri fi es that the program elements are available Precondition: Applicability
  19. 19. RBCreateAccessorsForVariableRefactoring >> preconditions ^ classVariable ifTrue: [ RBCondition de fi nesClassVariable: variableName asSymbol in: class ] ifFalse: [ RBCondition de fi nesInstanceVariable: variableName in: class ] Precondition: Applicability
  20. 20. Precondition: Applicability
  21. 21. • None • Applicability check • Break check • Complex ones Precondition: Break check
  22. 22. • None • Applicability check • Break check • Complex ones Precondition: Break check
  23. 23. • Veri fi es if the operation is done whether the system would be broken Precondition: Break check
  24. 24. RBRemoveClass >> preconditions ^ classNames inject: self emptyCondition into: [ :sum :each | | aClassOrTrait | aClassOrTrait := self model classNamed: each asSymbol. aClassOrTrait ifNil: [ self refactoringFailure: ’No such class or trait’ ]. sum & ((self preconditionIsNotMetaclass: aClassOrTrait) & (self preconditionHasNoReferences: each) & (self preconditionEmptyOrHasNoSubclasses: aClassOrTrait) & (self preconditionHasNoUsers: aClassOrTrait)) ] Precondition: Break check
  25. 25. Precondition: Break check
  26. 26. • Facing real code some things are not like in the books! • To be cleaned up! Precondition: Complex
  27. 27. RBPullUpMethod >> preconditions self requestSuperClass. ^(selectors inject: (RBCondition hasSuperclass: class) into: [:cond :each | cond & (RBCondition de fi nesSelector: each in: class)]) & (RBCondition withBlock: [self checkInstVars. self checkClassVars. self checkSuperclass. self checkSuperMessages. true]) RBPullUpMethod >> checkInstVarsFor: aSelector class instanceVariableNames do: [:each | ((class whichSelectorsReferToInstanceVariable: each) includes: aSelector) ifTrue: [ (self con fi rm: (’<1p> refers to #<2s> which is de fi ned in <3p>. Do you want push up variable #<2s> also ?’ expandMacrosWith: aSelector with: each with: class)) ifTrue: [ self pushUpVariable: each ] ifFalse: [ self refactoringError: ’You are about to push your method without the instance variable it uses. It will bring the system is an inconsistent state. But this may be what you want. So do you want to push up anyway?’ ] ]] RBPullUpMethod >> pushUpVariable: aVariable | refactoring | refactoring := RBPullUpInstanceVariableRefactoring model: self model variable: aVariable class: targetSuperclass. self performCompositeRefactoring: refactoring. Precondition: Complex
  28. 28. • Transformations can have preconditions too! Contrary to common beliefs
  29. 29. • What is basically the API that is used to perform changes? • Could such API turned into fi rst class transformation? Study the API of Program Model
  30. 30. Study the API of Program Model
  31. 31. • Analysed refactorings to identify atomic ones • And also which ones are modifying the program model Atomic refactorings and operations
  32. 32. • identify atomic Atomic refactorings and operations
  33. 33. • Studied the refactorings that directly use the program API elements • They could be turned into composite refactorings • Could the program API elements be turned into fi rst class transformations? Atomic refactorings and operations
  34. 34. Potential reuse
  35. 35. • Transformations can have preconditions too! • Interaction should be removed from refactorings • Identify Atomic refactorings • Identify potential reuse in implicit refactoring • Next step is to try to reify transformations and use them Conclusion

×