Slide 1

Slide 1 text

Towards a Framework for Software Design Defects Correction with Refactoring Plans Javier Pérez [email protected] Universidad de Valladolid Université de Mons-Hainaut Fundamental Aspects of Software Evolution FNRS Contact Group on Fundamental Computer Science May 22nd 2008, University of Namur Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 1 / 31

Slide 2

Slide 2 text

Introduction Introduction Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 2 / 31

Slide 3

Slide 3 text

Introduction Software Design Defects Definition Design defects are “bad” solutions to recurring design problems in object-oriented systems. Design defects are problems resulting from bad design practices. They include problems ranging from high-level and design problems, such as antipatterns, to low-level or local problems, such as code smells. (Moha, 2008) Why is important to deal with design defects? Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 3 / 31

Slide 4

Slide 4 text

Introduction Software Design Defects Definition Design defects are “bad” solutions to recurring design problems in object-oriented systems. Design defects are problems resulting from bad design practices. They include problems ranging from high-level and design problems, such as antipatterns, to low-level or local problems, such as code smells. (Moha, 2008) Why is important to deal with design defects? Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 3 / 31

Slide 5

Slide 5 text

Introduction Software Design Defects Definition Design defects are “bad” solutions to recurring design problems in object-oriented systems. Design defects are problems resulting from bad design practices. They include problems ranging from high-level and design problems, such as antipatterns, to low-level or local problems, such as code smells. (Moha, 2008) Why is important to deal with design defects? Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 3 / 31

Slide 6

Slide 6 text

Introduction Software Design Defects Definition Design defects are “bad” solutions to recurring design problems in object-oriented systems. Design defects are problems resulting from bad design practices. They include problems ranging from high-level and design problems, such as antipatterns, to low-level or local problems, such as code smells. (Moha, 2008) Why is important to deal with design defects? Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 3 / 31

Slide 7

Slide 7 text

Introduction Software Design Defects Definition Design defects are “bad” solutions to recurring design problems in object-oriented systems. Design defects are problems resulting from bad design practices. They include problems ranging from high-level and design problems, such as antipatterns, to low-level or local problems, such as code smells. (Moha, 2008) Why is important to deal with design defects? Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 3 / 31

Slide 8

Slide 8 text

Introduction Software Design Defects Definition Design defects are “bad” solutions to recurring design problems in object-oriented systems. Design defects are problems resulting from bad design practices. They include problems ranging from high-level and design problems, such as antipatterns, to low-level or local problems, such as code smells. (Moha, 2008) Why is important to deal with design defects? Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 3 / 31

Slide 9

Slide 9 text

Introduction Software Design Defects Definition Design defects are “bad” solutions to recurring design problems in object-oriented systems. Design defects are problems resulting from bad design practices. They include problems ranging from high-level and design problems, such as antipatterns, to low-level or local problems, such as code smells. (Moha, 2008) Why is important to deal with design defects? Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 3 / 31

Slide 10

Slide 10 text

Introduction Motivation Software evolution “happens”. Software design decays: changes are applied hastily “design debt” appears (Kerievsky, Refactoring To Patterns) Design decay can manifest through design defects, which affect software quality factors: maintainability reusability comprehensibility . . . Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 4 / 31

Slide 11

Slide 11 text

Introduction Motivation Software evolution “happens”. Software design decays: changes are applied hastily “design debt” appears (Kerievsky, Refactoring To Patterns) Design decay can manifest through design defects, which affect software quality factors: maintainability reusability comprehensibility . . . Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 4 / 31

Slide 12

Slide 12 text

Introduction Motivation Software evolution “happens”. Software design decays: changes are applied hastily “design debt” appears (Kerievsky, Refactoring To Patterns) Design decay can manifest through design defects, which affect software quality factors: maintainability reusability comprehensibility . . . Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 4 / 31

Slide 13

Slide 13 text

Introduction Software Design Defect Management The ideal is to prevent design defects, but . . . design defects appear, so systematic ways to detect and correct design defects are needed. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 5 / 31

Slide 14

Slide 14 text

Introduction Software Design Defect Management The ideal is to prevent design defects, but . . . design defects appear, so systematic ways to detect and correct design defects are needed. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 5 / 31

Slide 15

Slide 15 text

Introduction Software Design Defect Management The ideal is to prevent design defects, but . . . design defects appear, so systematic ways to detect and correct design defects are needed. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 5 / 31

Slide 16

Slide 16 text

Introduction Software Design Defect Management Techniques to detect design defects and to suggest design changes are maturing: Structural patterns to find defects (Moha, DECOR project) Metrics to detect “bad smells” (Marinescu, 2006; Crespo et al., 2005). Formal/Relational Concept Analysis to propose reorganisation of OO entities (Moha et al., 2006; Prieto et al., 2003). Software inconsistency management (Mens, 2006) The change suggestions given: are not directly applicable over a system, are usually given in terms of refactorings. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 6 / 31

Slide 17

Slide 17 text

Introduction Software Design Defect Management Techniques to detect design defects and to suggest design changes are maturing: Structural patterns to find defects (Moha, DECOR project) Metrics to detect “bad smells” (Marinescu, 2006; Crespo et al., 2005). Formal/Relational Concept Analysis to propose reorganisation of OO entities (Moha et al., 2006; Prieto et al., 2003). Software inconsistency management (Mens, 2006) The change suggestions given: are not directly applicable over a system, are usually given in terms of refactorings. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 6 / 31

Slide 18

Slide 18 text

Introduction Refactorings to Correct Design Defects Refactorings are structural transformations that can be applied to a software system to perform design changes without modifying its behaviour. Current approaches to improve a system design with refactorings focus in: Individual refactoring steps. Detecting refactoring opportunities. Assisting the developer in executing the refactoring Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 7 / 31

Slide 19

Slide 19 text

Introduction Refactorings to Correct Design Defects Refactorings are structural transformations that can be applied to a software system to perform design changes without modifying its behaviour. Current approaches to improve a system design with refactorings focus in: Individual refactoring steps. Detecting refactoring opportunities. Assisting the developer in executing the refactoring Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 7 / 31

Slide 20

Slide 20 text

Introduction Goals Objective of a Defect Correction Framework 1 Instantiate defect removing suggestions into a correction plan which could be effectively applied. through refactorings, because systems’ behaviour should be preserved. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 8 / 31

Slide 21

Slide 21 text

Introduction Goals Objective of a Defect Correction Framework 1 Instantiate defect removing suggestions into a correction plan which could be effectively applied. through refactorings, because systems’ behaviour should be preserved. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 8 / 31

Slide 22

Slide 22 text

Introduction Goals Refactoring Plans We pretend to introduce a new concept: Refactoring Plans Definition A Refactoring Plan will be a specification of a refactoring sequence which matches a system redesign proposal, so that it can be automatically executed to modify the system in order to obtain that desirable system redesign without changing the system’s behaviour. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 9 / 31

Slide 23

Slide 23 text

Introduction Goals Refactoring Plans We pretend to introduce a new concept: Refactoring Plans Definition A Refactoring Plan will be a specification of a refactoring sequence which matches a system redesign proposal, so that it can be automatically executed to modify the system in order to obtain that desirable system redesign without changing the system’s behaviour. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 9 / 31

Slide 24

Slide 24 text

Introduction Goals Refactoring Plans We pretend to introduce a new concept: Refactoring Plans Definition A Refactoring Plan will be a specification of a refactoring sequence which matches a system redesign proposal, so that it can be automatically executed to modify the system in order to obtain that desirable system redesign without changing the system’s behaviour. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 9 / 31

Slide 25

Slide 25 text

Introduction Goals Refactoring Plans We pretend to introduce a new concept: Refactoring Plans Definition A Refactoring Plan will be a specification of a refactoring sequence which matches a system redesign proposal, so that it can be automatically executed to modify the system in order to obtain that desirable system redesign without changing the system’s behaviour. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 9 / 31

Slide 26

Slide 26 text

Introduction Goals Refactoring Plans We pretend to introduce a new concept: Refactoring Plans Definition A Refactoring Plan will be a specification of a refactoring sequence which matches a system redesign proposal, so that it can be automatically executed to modify the system in order to obtain that desirable system redesign without changing the system’s behaviour. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 9 / 31

Slide 27

Slide 27 text

Introduction Goals Refactoring Plans We pretend to introduce a new concept: Refactoring Plans Definition A Refactoring Plan will be a specification of a refactoring sequence which matches a system redesign proposal, so that it can be automatically executed to modify the system in order to obtain that desirable system redesign without changing the system’s behaviour. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 9 / 31

Slide 28

Slide 28 text

Introduction Goals Refactoring Plans We pretend to introduce a new concept: Refactoring Plans Definition A Refactoring Plan will be a specification of a refactoring sequence which matches a system redesign proposal, so that it can be automatically executed to modify the system in order to obtain that desirable system redesign without changing the system’s behaviour. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 9 / 31

Slide 29

Slide 29 text

Introduction Goals Goals of a Framework for Refactoring Plans 1 Support to automatic or assisted generation of refactoring plans 2 To provide very high level (big) refactorings for design improvement, using refactoring plan generation altogether with the defect detection techniques that suggest redesign proposals. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 10 / 31

Slide 30

Slide 30 text

Introduction Goals Goals of a Framework for Refactoring Plans 1 Support to automatic or assisted generation of refactoring plans 2 To provide very high level (big) refactorings for design improvement, using refactoring plan generation altogether with the defect detection techniques that suggest redesign proposals. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 10 / 31

Slide 31

Slide 31 text

Design Defect Correction Design Defect Correction Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 11 / 31

Slide 32

Slide 32 text

Design Defect Correction General Defect Correction Process Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 12 / 31

Slide 33

Slide 33 text

Design Defect Correction Goals of a Framework for Refactoring Plans 1 Support to automatic or assisted generation of refactoring plans 2 To provide very high level (big) refactorings for design improvement, using refactoring plan generation altogether with the defect detection techniques that suggest redesign proposals. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 13 / 31

Slide 34

Slide 34 text

Design Defect Correction Goals of a Framework for Refactoring Plans 1 Support to automatic or assisted generation of refactoring plans 2 To provide very high level (big) refactorings for design improvement, using refactoring plan generation altogether with the defect detection techniques that suggest redesign proposals. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 13 / 31

Slide 35

Slide 35 text

Design Defect Correction A Framework sketch Software System Software Entity 1 1..* Design Defect Definition 1..* 1 Defect Symptom 1..* 1..* Metric Symptom Lexical/Semantic Smptom Structural Symptom 0..* 1..* Defect Correction Strategy Behaviour-Preserving Change Non Behaviour-Preserving Refactoring Suggestion Refactoring Plan 1..* 0..* Automated Refactorings 0..* 1..* Non-Automated Refactorings Class Interface Instance Methods Instance Variables Detected Defect 1..* 1..* Change 0..* 0..* 1..* 1..* Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 14 / 31

Slide 36

Slide 36 text

Generating Refactoring Plans Generating Refactoring Plans Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 15 / 31

Slide 37

Slide 37 text

Generating Refactoring Plans Problem description Refactoring Plan Questions Given a software system as the source of the transformation, a redesign proposal, and a set of refactorings that can be used as transformation operations: 1 Does a refactoring plan, which transforms the source, according to the redesign proposal, using the provided refactorings, exist? additional non-refactoring transformations could be needed 2 When a refactoring plan exists, can it be generated and executed automatically? How to deal with a semi-automated solution, with additional user input? Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 16 / 31

Slide 38

Slide 38 text

Generating Refactoring Plans Problem description Refactoring Plan Questions Given a software system as the source of the transformation, a redesign proposal, and a set of refactorings that can be used as transformation operations: 1 Does a refactoring plan, which transforms the source, according to the redesign proposal, using the provided refactorings, exist? additional non-refactoring transformations could be needed 2 When a refactoring plan exists, can it be generated and executed automatically? How to deal with a semi-automated solution, with additional user input? Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 16 / 31

Slide 39

Slide 39 text

Generating Refactoring Plans Problem description Refactoring Plan Questions Given a software system as the source of the transformation, a redesign proposal, and a set of refactorings that can be used as transformation operations: 1 Does a refactoring plan, which transforms the source, according to the redesign proposal, using the provided refactorings, exist? additional non-refactoring transformations could be needed 2 When a refactoring plan exists, can it be generated and executed automatically? How to deal with a semi-automated solution, with additional user input? Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 16 / 31

Slide 40

Slide 40 text

Generating Refactoring Plans Problem description Subproblems We have divided the problem of automatic generation of refactoring plans in: Definition and formalization of the “Refactoring Plan” concept Representation of Software Formalization of Refactorings Elaboration of techniques to obtain refactoring plans Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 17 / 31

Slide 41

Slide 41 text

Generating Refactoring Plans Refactoring Representation Formalising Refactorings Any refactoring formalization method must allow: to deal with system structure. to check behaviour preserving conditions. We will use Graph Transformations because: Representing and managing structural information is straightforward with graphs. This approach has already been validated (Mens et al., 2005). With Graph Transformation: Software is represented as graphs. Refactorings are represented as graph transformation rules. Other refactoring formalization approaches: First Order Logic (Kniessel, Köch, 2002). Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 18 / 31

Slide 42

Slide 42 text

Generating Refactoring Plans Refactoring Representation Example of a Graph Transformation Rule C P 2 4 M 1 p t I 3 i* C P 2 4 M 1 p t I 3 i* Left Hand Side Right Hand Side Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 19 / 31

Slide 43

Slide 43 text

Generating Refactoring Plans Software Representation Software Representation: Program Graphs A graph representation for Object-Oriented Software is needed. We must represent: elements of OO paradigm (classes, fields, methods, ...) structural relationships method bodies We have chosen the software representation part from the refactoring formalization of (Mens et al., 2005). This representation: uses directed type graphs. is language independent, lacking specific language constructions. has been simplified to be as flexible as possible. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 20 / 31

Slide 44

Slide 44 text

Generating Refactoring Plans Software Representation Software Representation: Program Graphs A graph representation for Object-Oriented Software is needed. We must represent: elements of OO paradigm (classes, fields, methods, ...) structural relationships method bodies We have chosen the software representation part from the refactoring formalization of (Mens et al., 2005). This representation: uses directed type graphs. is language independent, lacking specific language constructions. has been simplified to be as flexible as possible. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 20 / 31

Slide 45

Slide 45 text

Generating Refactoring Plans Software Representation Software Representation: Java Program Graphs C M MD E P V VD t p u a e c 1 1 p t i m l l m u a e Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 21 / 31

Slide 46

Slide 46 text

Generating Refactoring Plans Software Representation Software Representation: Java Program Graphs For real systems, it is necessary to extend the graph format, adding: elements for specific languages more detailed representation of method bodies We have extended program graphs for Java: Java Program Graphs. Our graph representation format adds: Java concepts such as visibility, interfaces, packages, . . . More detailed representation of method bodies, with new node types, attributes and relationships. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 22 / 31

Slide 47

Slide 47 text

Generating Refactoring Plans Software Representation Software Representation: Java Program Graphs For real systems, it is necessary to extend the graph format, adding: elements for specific languages more detailed representation of method bodies We have extended program graphs for Java: Java Program Graphs. Our graph representation format adds: Java concepts such as visibility, interfaces, packages, . . . More detailed representation of method bodies, with new node types, attributes and relationships. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 22 / 31

Slide 48

Slide 48 text

Generating Refactoring Plans Software Representation Software Representation: Java Program Graphs For real systems, it is necessary to extend the graph format, adding: elements for specific languages more detailed representation of method bodies We have extended program graphs for Java: Java Program Graphs. Our graph representation format adds: Java concepts such as visibility, interfaces, packages, . . . More detailed representation of method bodies, with new node types, attributes and relationships. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 22 / 31

Slide 49

Slide 49 text

Generating Refactoring Plans Software Representation Software Representation: Java Program Graphs Package name : String Class isFinal : boolean Interface implements 0..* 0..* Variable name : String visibility : String isAbstract : boolean isStatic : boolean isFinal : boolean Operation name : String visibility : String isAbstract : boolean isStatic : boolean isFinal : boolean Parameter MethodBody binding 0..* 1 belongsTo 0..* 0..1 belongsTo 1 0..* belongsTo 0..* 1 belongsTo 0..* 0..1 Literal value : String type 0..* 1 Expression belongsTo 0..* 0..1 expression 0..* {ordered} 0..* Access this : boolean Call this : boolean super : boolean Operator name : String Update this : boolean Instantiation {incomplete} Return Block belongsTo 1 1 ActualParameters expression 1 0..1 Classifier name : String visibility : String isAbstract : boolean belongsTo 1 1..* imports 0..* 0..* extends 0..* 0..* type 0..* 1 type 0..1 0..* type 1 0..* parameter 1 0..* {ordered} link 0..1 0..* link 0..* 0..1 link 0..* 0..1 link 0..* 0..1 link 0..* 0..1 belongsTo 0..1 0..* link 1 0..1 {ordered} expression 1 1..* {ordered} Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 23 / 31

Slide 50

Slide 50 text

Generating Refactoring Plans Software Representation Possible Approaches to Obtain Refactoring Plans We are exploring two aproaches: Searching forwards Searching backwards Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 24 / 31

Slide 51

Slide 51 text

Generating Refactoring Plans Software Representation Searching forwards approach Suggested changes are turned into a simplified version of the sstem’s desirable design. Available refactorings are applied in a state space search way. Refactoring pre and postconditions guide the search. Advantages Every possible path is being explored Relatively easy to implement Problems Size of the state space Possible infinite process Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 25 / 31

Slide 52

Slide 52 text

Generating Refactoring Plans Software Representation Searching Backwards approach Dependencies between refactorings are computed Iteratively, refactorings which enable the application of the desired change are added to the plan. Advantages More efficient than searching backwards Problems More difficult to implement with current Graph Transformation tools Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 26 / 31

Slide 53

Slide 53 text

Generating Refactoring Plans Software Representation Open questions Can complex refactorings be represented and analysed with current GT tools? Can searching be reduced to finite process? Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 27 / 31

Slide 54

Slide 54 text

Conclusions and Future Work Conclusions and Future Work Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 28 / 31

Slide 55

Slide 55 text

Conclusions and Future Work Conclusions Automatic generation of refactoring plans will provide very high level refactorings to improve the design of existing code. The Main subproblems and the research strategy have been introduced. Graph transformation can be used as the underlying formalism, specifically the programmed graph rewriting approach. Representing Java programs with Java Program Graphs. The graph transformation formalism could provide support to refactorings formal analysis, enabling searching for refactoring plans. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 29 / 31

Slide 56

Slide 56 text

Conclusions and Future Work Conclusions Automatic generation of refactoring plans will provide very high level refactorings to improve the design of existing code. The Main subproblems and the research strategy have been introduced. Graph transformation can be used as the underlying formalism, specifically the programmed graph rewriting approach. Representing Java programs with Java Program Graphs. The graph transformation formalism could provide support to refactorings formal analysis, enabling searching for refactoring plans. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 29 / 31

Slide 57

Slide 57 text

Conclusions and Future Work Conclusions Automatic generation of refactoring plans will provide very high level refactorings to improve the design of existing code. The Main subproblems and the research strategy have been introduced. Graph transformation can be used as the underlying formalism, specifically the programmed graph rewriting approach. Representing Java programs with Java Program Graphs. The graph transformation formalism could provide support to refactorings formal analysis, enabling searching for refactoring plans. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 29 / 31

Slide 58

Slide 58 text

Conclusions and Future Work Future Work Main future tasks will be directed to: Further definition of the “Refactoring Plan” concept. Explore the expressivenss of GT tools Analyse termination and correctness conditions of the searching approaches. Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 30 / 31

Slide 59

Slide 59 text

Conclusions and Future Work Towards a Framework for Software Design Defects Correction with Refactoring Plans Javier Pérez [email protected] Universidad de Valladolid Université de Mons-Hainaut Fundamental Aspects of Software Evolution FNRS Contact Group on Fundamental Computer Science May 22nd 2008, University of Namur Javier Pérez (UVa, UMH) A Framework for Refactoring Plans May 2008 31 / 31