Model Refactoring Using Transformations
Total Page:16
File Type:pdf, Size:1020Kb
MODEL REFACTORING USING TRANSFORMATIONS THÈSE NO 4031 (2008) PRÉSENTÉE LE 23 MAI 2008 PRÉSENTÉE À LA FACULTÉ INFORMATIQUE ET COMMUNICATIONS Institut des systèmes informatiques et multimédias SECTION D'INFORMATIQUE ÉCOLE POLYTECHNIQUE FÉDÉRALE DE LAUSANNE POUR L'OBTENTION DU GRADE DE DOCTEUR ÈS SCIENCES PAR Slaviša MARKOVIC´ Bachelor of Science in Information Systems Engineering, University of Belgrade, Serbie et de nationalité serbe acceptée sur proposition du jury: Prof. E. Telatar, président du jury Dr T. Baar , directeur de thèse Prof. D. Buchs, rapporteur Prof. J.-M. Jézéquel, rapporteur Prof. A. Wegmann, rapporteur Lausanne, EPFL 2008 Abstract Modern software is reaching levels of complexity encountered in biological systems; sometimes comprising systems of systems each of which may include tens of millions of lines of code. Model Driven Engineering (MDE) advocates raising the level of abstraction as an instrument to deal with software complexity. It promotes usage of software models as primary artifacts in a software development process. Tradi- tionally, these MDE models are specified by Unified Modeling Language (UML) or by a modeling language created for a specific domain. However, in the vast area of software engineering there are other techniques used to improve quality of software under development. One of such techniques is refactoring which represents introducing structured changes in software in order to improve its readability, extensibility, and maintainability, while preserving behavior of the software. The main application area for refactorings is still programming code, despite the fact that modeling languages and techniques has significantly gained in popularity, in recent years. The main topic of this thesis is making an alliance between the two virtually orthogonal techniques: software modeling and refactoring. In this thesis we have investigated how to raise the level of abstraction of programming code refactorings to the modeling level. This resulted in a catalog of model refactorings each specified as a model transformation rule. In addition, we have investigated synchronization problems between different models used to describe one software system, i.e. when one model is refactored what is the impact on all dependent models and how this impact can be formalized. We have concentrated on UML class diagrams as domain of refactorings. As models dependent on class diagrams, we have selected Object Constraint Language (OCL) annotations, and object diagrams. This thesis formalizes the most important refactoring rules for UML class diagrams and classifies them with respect to their impact on object diagrams and annotated OCL constraints. For refactoring rules i ii that have an impact on dependent artifacts we formalize the necessary changes of these artifacts. Moreover, in this thesis, we present a simple criterion and a proof technique for the semantic preservation of refactoring rules that are defined for UML class and object diagrams, and OCL constraints. In order to be able to prove semantic preservation, we propose a model transformation approach to specify the semantics of constraint languages. Keywords Model Driven Engineering, UML, Model Transformations, Refactoring, QVT, OCL Semantics, Semantics Preservation Resum´ e´ La complexit´edes logiciels actuels atteint des niveaux comparables `aceux ren- contr´eschez les syst`emes vivants. Parfois, des syst`emeslogiciels peuvent en en- glober d'autres d´ej`aeux-m^emescompos´esde dizaines de millions de lignes de code. L'Ing´enierieDirig´eepar les Mod`eles(IDM) pose l'abstraction en instrument de gestion de cette complexit´e.Pour ce faire, l'IDM promeut les mod`elescomme com- posants principaux d'un processus de d´eveloppement logiciel. Souvent, ces mod`eles sont exprim´essoit en utilisant le langage UML (Unified Modeling Language), soit dans un langage sp´ecifiqueau domaine concern´e. Cependant, le domaine du g´enie logiciel est tr`esvaste, et il existe d'autres tech- niques `am^emed'am´eliorerla qualit´ed'un syst`emelogiciel lors de son d´eveloppement. Une de ces techniques est le r´eusinage(ou refactorisation), plus connue sous sa d´enominationanglaise de refactoring. Cette technique permet de restructurer un code logiciel de mani`ere`ale rendre plus lisible, plus souple, ou plus facile `amaintenir. Cependant, malgr´ele r´ecent succ`esdes langages et techniques de mod´elisation,la principale cible d'application du refactoring reste le code programme. Le sujet principal de cette th`eseest d'associer ces deux techniques a priori or- thogonales que sont la mod´elisationet le refactoring. Dans cette th`ese,nous avons port´ela technique refactoring pour la mettre au service de la mod´elisation. Comme r´esultat,nous proposons ici un catalogue de refactorings de mod`ele, tous exprim´es par une transformation de mod`ele.De plus, nous avons pris en compte le probl`eme de la coh´erenceentres les diff´erents mod`elesd´ecrivant un syst`emelogiciel. Il est en effet n´ecessairede d´efinircomment un refactoring doit impacter les mod`eles d´ependants du mod`eleinitialement restructur´e. Nous nous sommes ici concentr´essur le refactoring des diagrammes de classes du langage UML, dont sont d´ependants les mod`elesde contraintes en OCL (Ob- ject Constraint Language) et les diagrammes d'objets. Cette th`eseformalise des refactorings parmi les plus importants pour les diagrammes de classes UML, tout iii iv en les triant suivant leur impact sur les diagrammes d'objets ainsi que les mod`eles de contraintes OCL, impact que nous formaliserons ´egalement. En outre, nous pr´esentons ici une technique de preuve, bas´eesur un crit`ere simple, pour la pr´eservation s´emantique des diagrammes de classes, des diagrammes d'objets et des contraintes, une fois appliqu´eun refactoring. Cependant, afin prouver formellement une pr´eservation s´emantique, il est n´ecessaired'avoir `adisposition une description formelle de ladite s´emantique; nous proposons donc ´egalement un approche de description de la s´emantique bas´eesur les transformations de mod`eles que nous appliquons au langage OCL. Mot Clefs Ing´enierieDirig´eepar les Mod`eles,UML, Transformations de Mod`eles,Refactorisa- tion, QVT, S´emantique d'OCL, Pr´eservation de la S´emantique Acknowledgments First of all, I wish to express my sincere gratitude to my advisor, Dr. Thomas Baar, for his counsel, guidelines, and help that he provided during all these years I spent at EPFL. Thomas managed to be not only an excellent supervisor but at the same time a good friend always ready to help. This combination made my work at EPFL a pleasant experience. I would like to thank all the jury members Prof. Didier Buchs, Prof. Jean-Marc J´ez´equel,and Prof. Alain Wegmann for having taken the time and effort to review my thesis and to serve on my examination board. I am greatly indebted to Prof. Alfred Strohmeier for accepting me as a student in his lab, and giving me a chance to work on a PhD. Special thanks to Fr´ed´ericFondement for reviewing this thesis and giving a lot of precious comments that improved its quality, and to Shane Sendall for helping me "surviving" my first steps as a PhD student. I would like to thank members of the RoclET team C´edricJeanneret and Leander Eyer for implementing ideas expressed in this thesis. I was very fortunate to work in the pleasant and motivating scientific atmosphere of the Software Engineering Laboratory (LGL). I would like to thank previous LGL members for their support and friendliness: Mohamed Kand´e,Jarle Hulaas, Rodrigo Garc`ıa,Raul Silaghi, Andrea Camesi, Benjamin Barras, Isabelle Moinon, and J¨org Kienzle. Also, I would like to thank members of the Software Modeling and Veri- fication Group from University of Geneva, and the Systemic Modeling Laboratory from EPFL, for their encouragement and help in the very finish of my PhD studies. I would like to thank friends from (not so) small Serbian community at EPFL for making my life in Switzerland much easier. Finally, I would like to thank mama Desanka, tata Milorad, Nina, and Nikola for their unconditional support, encouragement, and patience during my everlasting studies. This work is dedicated to them. v vi Contents List of Figures xiv 1 Introduction 1 1.1 Motivation . 2 1.2 Scope . 3 1.3 Thesis Contributions and Outline . 4 1.3.1 Contributions . 4 1.3.2 Plan . 4 2 Key Concepts 7 2.1 The Unified Modeling Language . 7 2.1.1 Class Diagrams . 8 2.1.2 Object Diagrams . 8 2.1.3 Object Constraint Language . 9 2.2 Refactorings . 10 2.3 Metamodeling . 12 2.4 Metamodel of UML/OCL . 12 2.4.1 Declaration of Metaclasses . 13 2.4.2 Well-formedness Rules . 14 2.5 Model Transformations and QVT . 16 2.5.1 How to Write Syntax Preserving QVT Rules . 19 2.5.2 Extends-Relationship between QVT Rules . 23 3 Refactoring UML/OCL Diagrams 27 3.1 Introduction . 27 3.2 A Catalog of UML/OCL Refactoring Rules . 28 3.2.1 Rules Without Influence on OCL . 28 vii viii CONTENTS 3.2.2 Rules With Influence on OCL . 36 3.2.3 Reformulation of Refactoring Rules for UML 2.0 . 41 3.3 Proving the Preservation of Well-formedness Rules . 44 3.4 Related Work . 49 3.5 Conclusions . 49 4 Model Transformations for Describing Semantics of OCL 51 4.1 Introduction . 52 4.2 A Metamodel-Based Approach for OCL Evaluation . 54 4.2.1 Changes in the OCL Metamodel . 54 4.2.2 Evaluation . 56 4.2.3 Binding . 58 4.3 Core Evaluation Rules Formalized as Model Transformations . 59 4.3.1 Model Transformation Rules . 59 4.3.2 Binding Passing . 60 4.3.3 A Catalog of Core Rules . 61 4.3.4 Syntactic Sugar . 73 4.4 Semantic Concepts in OCL . 74 4.4.1 Evaluation of Operation Contracts .