Save 37% off PRO during our Black Friday Sale! »

Refactoring Planning for Design Smell Correction: Summary, Opportunities and Lessons Learned

7e6a5857a7eb4501c63ab00481ac3305?s=47 Javier Pérez
September 24, 2013

Refactoring Planning for Design Smell Correction: Summary, Opportunities and Lessons Learned

Complex refactoring processes, such as applying big refactorings or removing design smells are difficult to perform in practice. The complexity of these processes is partly due to their heuristic nature and to the constraints imposed by preconditions on the applicability of the individual refactorings. Developers have to find out manually how to apply a complex refactoring “recipe”, from a refactoring book, for each particular situation. In a PhD thesis, we developed an approach for tackling this problem. We described how to better write refactoring “recipes” (Refactoring Strategies) and how to compute, from them, the precise refactoring sequences for each particular situation (Refactoring Plans). Our proposal introduced, for the first time, the use of automated planning for this kind of software engineering problems. This paper presents a short summary of that PhD thesis and discuss the future work, open questions, new research opportunities arisen and the lessons learned from it. Presented at ICSM 2013 (http://icsm2013.tue.nl).

7e6a5857a7eb4501c63ab00481ac3305?s=128

Javier Pérez

September 24, 2013
Tweet

Transcript

  1. September 24th 2013 - ICSM 2013 - Doctoral Symposium -

    Postdoctoral session Javier Pérez Refactoring Planning for Design Smell Correction: Summary, Opportunities and Lessons Learned Tuesday 24 September 13
  2. Only Simple Refactorings! How do we refactor? Simple tools? Tuesday

    24 September 13
  3. What refactorings do we use? Eclipse Usage Data Collector -

    http://www.eclipse.org/org/usagedata/results.php? kind=command&sort=element http://stackoverflow.com/questions/1804839/eclipse-most-useful-refactorings Tuesday 24 September 13
  4. How should we refactor? Recipes! Only textual descriptions! “Bad Smells

    in Code” chapter 3 Disharmonies chapters 5, 6, 7 Cheatsheet “Smells to Refactorings” Tuesday 24 September 13
  5. PrintServer formatSummary(): String setLastDocument(d: Document): void getLastDocument: Document printDocument(): void

    lastDocument: Document formatDocument: String formatSummary(): String content: String name: String author: String creationDate: Date Document Complex Refactoring Processes ✤ Feature Envy: PrinterServer.formatSummary() ✤ Strategy: move method from PrintServer to Document ✤ Plan: ✤ rename Document.formatSummary() ✤ move PrintServer.formatSummary() Tuesday 24 September 13
  6. Refactoring Strategy Refactoring Strategies and Plans “Refactoring Planning for Design

    Smell Correction in Object-Oriented Software” PhD Thesis, July 2011, University of Valladolid, spain Tuesday 24 September 13
  7. Remove Data Class Strategy remove-data-class all-sts (class) remove-data-class reorganize-class (class)

    remove-class (class) remove-data-class trivial (class) refactoring alt apply strategy (refact.) strategy (smell) remove-data-class clean-class (class) encapsulate-field (field, getter-name, setter-name) encapsulate-fields non-private (class) remove-getters unused (class) remove-setters unsued (class) remove-feature-envy move-method-to-envied-class (method, env-class) move-method all-sts (method, tgt-class, reference) remove-method (accessor) remove-data-class move-fe-methods (class) remove-data-class move-client-methods (class) Tuesday 24 September 13
  8. Refactoring Strategy Refactoring Plans Refactoring Planner Refactoring Strategy Vn current

    Refactoring Strategies and Plans “Refactoring Planning for Design Smell Correction in Object-Oriented Software” PhD Thesis, July 2011, University of Valladolid, spain Tuesday 24 September 13
  9. Hierarchical Task Network (HTN) Planning ✤ Operators: Low level changes

    - add / remove AST elements ✤ Tasks: Methods and operators - “recipes” about how to execute a task ✤ Preconditions: first-order-logic queries - gather system information ✤ Goal: Execute a task method1 precondition1 task1 task2 task3 ... method2 precondition2 task4 operator1 precondition3 ADD DEL Goal Execute a task Tuesday 24 September 13
  10. Remove Data Class Plan apply-refactoring:! ! show-method (org.jwebap.asm.attrs, stackmapattribute, gettypeinfolabels)

    apply-refactoring:! ! move-method (from, org.jwebap.asm.attrs, stackmapattribute, getframelabels, to, org.jwebap.asm.attrs, stackmapframe, through, frame, keeping-delegate, false) apply-refactoring:! ! show-method (org.jwebap.asm.attrs, stackmapattribute, writetypeinfo) apply-refactoring:! ! move-method (from, org.jwebap.asm.attrs, stackmapattribute, writeframe, to, org.jwebap.asm.attrs, stackmapframe, through, frame, keeping-delegate, false) apply-refactoring:! ! show-method (org.jwebap.asm.util.attrs, asmstackmapattribute, asmify) apply-refactoring:! ! show-method (org.jwebap.asm.util.attrs, asmstackmapattribute, declarelabel) apply-refactoring:! ! show-method (org.jwebap.asm.util.attrs, asmstackmapattribute, asmifytypeinfo) apply-refactoring:! ! move-method (from, org.jwebap.asm.util.attrs, asmstackmapattribute, asmify, to, org.jwebap.asm.attrs, stackmapframe, through, f keeping-delegate, false) apply-refactoring:! ! encapsulate-field (org.jwebap.asm.attrs, stackmapframe, label, getlabel, setlabel) apply-refactoring:! ! encapsulate-field (org.jwebap.asm.attrs, stackmapframe, locals, getlocals, setlocals) apply-refactoring:! ! encapsulate-field (org.jwebap.asm.attrs, stackmapframe, stack, getstack, setstack) apply-refactoring:! ! remove-method(org.jwebap.asm.attrs, stackmapframe, setlabel) (SETTER) apply-refactoring:! ! remove-method(org.jwebap.asm.attrs, stackmapframe, setlocals)(SETTER) apply-refactoring:! ! remove-method(org.jwebap.asm.attrs, stackmapframe, setstack) (SETTER) apply-remove-smell:! remove-data-class (org.jwebap.asm.attrs, stackmapframe) cleanclass Tuesday 24 September 13
  11. Refactoring Strategy Refactoring Plans Refactoring Planner Refactoring Strategy Vn current

    Refactoring Plans Refactoring Planner Refactoring Tool Refactoring Strategy Vn+1 improved design Vn current Refactoring Strategies and Plans “Refactoring Planning for Design Smell Correction in Object-Oriented Software” PhD Thesis, July 2011, University of Valladolid, spain Tuesday 24 September 13
  12. Opportunities and Future Work Tuesday 24 September 13

  13. Refactoring Planning Domain ✤ 3 Refactoring Strategies: ✦ for removing

    design smells ‣ Remove Data Class and Remove Feature Envy ✦ for applying a complex refactoring ‣ Move Method ✤ 9 Refactorings: ✦ Encapsulate Field, Move Method, Rename Method, Rename Field, Rename Parameter, Rename Local Variable, Remove Field, Remove Method and Remove Class. ✤ > 150 system queries: Crowsourcing development knowledge: !! ! ! ! ! ! ! Mining Refactoring Strategies Tuesday 24 September 13
  14. Refactoring Strategy Crowsourcing development knowledge: !! ! ! ! !

    ! ! Mining Refactoring Strategies Tuesday 24 September 13
  15. V1 ... Vn Refactoring Finder Smell Finder Strategy Miner Refactoring

    Strategy S1 ... Sn R1 ... Rn Crowsourcing development knowledge: !! ! ! ! ! ! ! Mining Refactoring Strategies Tuesday 24 September 13
  16. V1 ... Vn Refactoring Finder Smell Finder Strategy Miner Refactoring

    Strategy S1 ... Sn R1 ... Rn Available Mature Tools Our goal Crowsourcing development knowledge: !! ! ! ! ! ! ! Mining Refactoring Strategies Ref-Finder Tuesday 24 September 13
  17. Opportunities and Future Work • Automated planning for other task

    scheduling problems in Software Reengineering • Composite Refactoring Detection • Model Inconsistencies Removal Resolving model inconsistencies using automated regression planning; Pinna-Puissant et.al., 2013 Identifying composite refactorings with a scripting language; Huang et.al., 2011 Tuesday 24 September 13
  18. Lessons Learned - technical • There is a need to

    implement big refactorings • Try not to automate too much • Big refactorings should be implemented “empirically” - with recipes • Reasoning should be done with the full AST information Tuesday 24 September 13
  19. Lessons Learned - general • Invest enough time to find

    and define a realistic, relevant and feasible problem • Ask the experts • Research stays are a great investment • Writing helps a lot settling things down • Persevere! Tuesday 24 September 13
  20. Summary Tuesday 24 September 13

  21. September 24th 2013 - ICSM 2013 - Doctoral Symposium -

    Postdoctoral session Javier Pérez Refactoring Planning for Design Smell Correction: Summary, Opportunities and Lessons Learned Tuesday 24 September 13