Slide 1

Slide 1 text

Automated Elaboration of Refactoring Plans F. Javier Pérez García [email protected] Departamento de Informática Universidad de Valladolid Valladolid, Spain Automated Elaboration of Refactoring Plans – p.1

Slide 2

Slide 2 text

Slides Index • Introduction • Refactoring Plan Issues • Approach • Example • Results and Future Work Automated Elaboration of Refactoring Plans – p.2

Slide 3

Slide 3 text

Introduction Automated Elaboration of Refactoring Plans – p.3

Slide 4

Slide 4 text

Introduction: Refactoring Automation Current approaches to refactoring automation: • automation focus on finding and applying single refactoring opportunities • oriented to improve certain design characteristics In some cases, deeper redesign is needed: • wider architectural changes • starting a framework based product-line from legacy software Other refactoring methodologies are needed. Automated Elaboration of Refactoring Plans – p.4

Slide 5

Slide 5 text

Introduction: Refactoring Plan Start with a desirable system design proposal: • Formal concept Analysis • skilled human designer • metrics Refactoring Plan: chain of refactorings to reach a proposed new design. Automated elaboration of Refactoring Plans: • new design, reachable with a refactoring sequence? • which is the refactoring sequence? Automated Elaboration of Refactoring Plans – p.5

Slide 6

Slide 6 text

Refactoring to a Desirable Design Automated Elaboration of Refactoring Plans – p.6

Slide 7

Slide 7 text

Refactoring Plan Issues Automated Elaboration of Refactoring Plans – p.7

Slide 8

Slide 8 text

A GRS Problem A kind of Formal Language Problem: Finding the transformation steps that turn a state into another. Representing software, specially its structural relationships is straightforward with graphs. Problem Representation: • Software ⇒ Graphs • Software Transformations ⇒ Graph Rewriting Systems Automated elaboration of Refactoring Plans can be represented as a Graph Rewriting/Transformation Problem Automated Elaboration of Refactoring Plans – p.8

Slide 9

Slide 9 text

Finding the refactoring Plan, with GRSs Use a Graph Grammar (GG) where: • Legacy Software System ⇒ Starting State • Refactorings ⇒ Production Rules • Desirable Design ⇒ Final State Validating the desirable design ⇒ membership problem. Obtaining the Refactoring Plan ⇒ Obtaining the derivation sequence. Automated Elaboration of Refactoring Plans – p.9

Slide 10

Slide 10 text

Graph Rewriting Based Approach Automated Elaboration of Refactoring Plans – p.10

Slide 11

Slide 11 text

Formal Representation of OO Software Need to represent: • OO elements (Classes, fields, methods, . . . ) • method’s bodies • structural relationships Mens et al. Formalism: • GRS system based on directed typed graphs • aimed at formalizing refactorings • supports: ◦ Constraints and well formedness rules ◦ Graph transformation rules ◦ behavior preserving invariants ◦ specification of complex context of rules (NAC, node embeddings, path expressions) Automated Elaboration of Refactoring Plans – p.11

Slide 12

Slide 12 text

Finding a Refactoring Plan Write refactoring rules within a GG for which the membership problem is solved. Contextual Layered Graph Grammars (CLGGs): • extension of Layered Graph Grammars (LGGs) • rules are classified in subsets of ordered layers • parsing: ◦ rules are applied by layer order ◦ creation-deletion of single element of same type ◦ each step, graph is reduced ◦ each step, applicable rules are reduced • specification of complex context of rules (NAC, node embeddings, path expressions) Automated Elaboration of Refactoring Plans – p.12

Slide 13

Slide 13 text

Micro-Refactorings Layering Refactoring rules providing graph and rule reduction: • use refactoring rules inspired by CLGGs • refactorings are ordered and assigned different layers • need rules for single element refactorings • each layer aimed at an element type Micro-Refactorings: • based on Opdyke’s low-level refactorings • small behavior preserving operations: ◦ create, delete, move, rename ◦ single elements: classes, methods, . . . • limit the number of times a rule is applicable over an element Automated Elaboration of Refactoring Plans – p.13

Slide 14

Slide 14 text

Example Automated Elaboration of Refactoring Plans – p.14

Slide 15

Slide 15 text

Micro-Refactoring Rules Three simple rules: • Create unreferenced empty Class • Create unreferenced empty Method • Move method to empty method Restrictions to reduce applicable set of rules: • Specific counters for each rule • Rule layering ◦ 0: Create Class ◦ 1: Create Method ◦ 2: Move Method Automated Elaboration of Refactoring Plans – p.15

Slide 16

Slide 16 text

Create unreferenced empty Class Automated Elaboration of Refactoring Plans – p.16

Slide 17

Slide 17 text

Create unreferenced empty Method Automated Elaboration of Refactoring Plans – p.17

Slide 18

Slide 18 text

Move method to empty method Automated Elaboration of Refactoring Plans – p.18

Slide 19

Slide 19 text

Small Example Preferences protocol() printMe() Address connection() printMe() SetUp settings() 1 1 Automated Elaboration of Refactoring Plans – p.19

Slide 20

Slide 20 text

Desirable System Design Preferences protocol() printMe() Address connection() printMe() SetUp settings() protocol(pref:Preferences) Connect connection(addr:Address) 1 1 1 1 Automated Elaboration of Refactoring Plans – p.20

Slide 21

Slide 21 text

Starting System Graph Automated Elaboration of Refactoring Plans – p.21

Slide 22

Slide 22 text

Layer 0: Class created Automated Elaboration of Refactoring Plans – p.22

Slide 23

Slide 23 text

Layer 1: Method created Automated Elaboration of Refactoring Plans – p.23

Slide 24

Slide 24 text

Layer 2: Methods Moved Automated Elaboration of Refactoring Plans – p.24

Slide 25

Slide 25 text

Results and Future Work Automated Elaboration of Refactoring Plans – p.25

Slide 26

Slide 26 text

Results • An initial step of the research has been presented • Requirements for Automated elaboration of Refactoring Plans has been stated • Formalisms to be used have been explored • Mens formalism can fulfill our requirements • CLGGs are OK, but more grammars must been explored Automated Elaboration of Refactoring Plans – p.26

Slide 27

Slide 27 text

Future Work • • Prove that micro-refactorings can be composed into “normal” refactorings • Catalog of micro-refactorings & decomposed refactorings • Extensive validation through tools like AGG, FUJABA or PROGRES • Extensions to formalisms and tools if needed • Improve rules to full automatize the process Automated Elaboration of Refactoring Plans – p.27

Slide 28

Slide 28 text

Automated Elaboration of Refactoring Plans F. Javier Pérez García [email protected] Departamento de Informática Universidad de Valladolid Valladolid, Spain Automated Elaboration of Refactoring Plans – p.28