generic model refactorings - colorado state university · generic model refactorings naouel moha,...

25
Generic Model Refactorings Naouel Moha , Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes Bretagne Atlantique/IRISA, Université Rennes 1, France MODELS’09 October 4 - 9, 2009

Upload: others

Post on 14-Mar-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Generic Model Refactorings

Naouel Moha, Vincent Mahé,

Olivier Barais, and Jean-Marc Jézéquel

Triskell Team, INRIA Rennes – Bretagne Atlantique/IRISA, Université Rennes 1, France

MODELS’09October 4 - 9, 2009

Page 2: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Context

Generic Model Refactorings

UML Metamodel

Java MetamodelMOF Metamodel Common

Concepts

Generalization

Parameter

Property

Class

Operation

Parameter

Class

ParameterProperty

Operation

Operation

Variable

ClassDefinition

Page 3: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Context

Generic Model Refactorings

UML Metamodel

Java MetamodelMOF Metamodel

MT : Refactoring

The metamodels may be structurally different

Page 4: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Context

Generic Model Refactorings

UML Metamodel

Java MetamodelMOF Metamodel

The metamodel elements may have different names

Page 5: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Context

Generic Model Refactorings

UML Metamodel

Java MetamodelMOF Metamodel

UML Metamodel

MOF MetamodelMOF Metamodel

UML Metamodel

There may be additional or missing elements

Page 6: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Context

Generic Model Refactorings

UML Metamodel

Java MetamodelMOF Metamodel

The types of elements may be different

Page 7: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Context

Generic Model Refactorings

Java MetamodelMOF Metamodel

UML Metamodel

The way metamodel classes are linked together may be different

UML Metamodel

Page 8: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Context

Generic Model Refactorings

UML Metamodel

Java MetamodelMOF Metamodel

UML : Refactoring

Java : RefactoringMOF : Refactoring

Page 9: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Goal

Generic : Refactoring

Generic Model Refactorings

UML Metamodel

Java Metamodel

Code Reuse in MDE

MOF Metamodel

Page 10: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Approach

Generic Model Refactorings

Specification of

Generic Metamodel

GenericMM

1

Specification of

Generic Refactorings

2

Adaptation of

Target Metamodels

3

Java

Metamodel

package refactor;

class Refactor

<MT : GenericMT>{

operation

encapsulateField(

...

end

}

Refactoring in

Kermeta

UML Model

Refactored

Java Model

Refactored

Application of

Refactoring

4

UML

Metamodel

MOF

Metamodel

UML

Model

Java

Model

MOF

Model

MOF Model

Refactored

Based on aspect weaving and model typing [Steel 07, SoSyM]

Page 11: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Model Typing

Generic Model Refactorings

Metamodel MMMetamodel MM’

Does the metamodel MM’ match the metamodel MM ?

Metamodel MM’ matches another metamodel MM iff for each class C in MM,

there is one and only one corresponding class C’ in MM’

0..1aCTwo

0..1 aC2

match ?

match ?

match ?

Set of rules guarantees a subtype relationship btw the two MMs [Steel 07, SoSyM]

If T works for MM, and if MM' is a model subtype of MM, then T works with MM'

Page 12: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Approach

Generic Model Refactorings

Specification of

Generic Metamodel

GenericMM

1

Specification of

Generic Refactorings

2

Adaptation of

Target Metamodels

3

Java

Metamodel

package refactor;

class Refactor

<MT : GenericMT>{

operation

encapsulateField(

...

end

}

Refactoring in

Kermeta

UML Model

Refactored

Java Model

Refactored

Application of

Refactoring

4

UML

Metamodel

MOF

Metamodel

UML

Model

Java

Model

MOF

Model

MOF Model

Refactored

Page 13: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Step 1: Specification of Generic Metamodel

Generic Model Refactorings

Approach

Page 14: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Approach

Generic Model Refactorings

Step 2: Specification of Generic Refactorings

Generic MetamodelGenericMM : Refactoring

Page 15: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Approach

Generic Model Refactorings

Step 2: Specification of Generic Refactorings

Generic MetamodelGenericMM : Refactoring

Page 16: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Approach

Generic Model Refactorings

Step 3: Adaptation of Target Metamodels

Generic Metamodel Java Metamodel

matches ?matches ? Yes!

inv_extends

Page 17: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Approach

Generic Model Refactorings

Step 3: Adaptation of Target Metamodels

Generic Metamodel Java Metamodel

matches ?matches ? Yes!

inv_extends

Page 18: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Approach

Generic Model Refactorings

Step 3: Adaptation of Target Metamodels

Generic MetamodelUML Metamodel

inv_general

Page 19: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Approach

Generic Model Refactorings

Step 3: Adaptation of Target Metamodels

Generic MetamodelUML Metamodel

inv_general

Page 20: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha © Generic Model Refactorings

Approach

Step 4: Application of Refactoring

Class Refactor <MT : GenericMM>

Var refactor : Refactor::Refactor<uml::UmlMM>

refactor.moveMethod(meth,source, target)

The Target metamodel is a subtype of the expected supertype GenericMM

Page 21: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Approach

Generic Model Refactorings

Discusions

The adaptation is necessary because metamodels are structurally

different

The adaptation virtually modifies the structure of the target

metamodel with additional elements

Model typing guarantees the type conformance between the target

metamodels and the generic metamodel

Page 22: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

4th metamodel

Ambiguous match : 2 classes of the generic MM were unified in a

same class

Limitation : each element in the generic MM should correspond to

a distinct element in the target MM

Case Study

Goal : Validate our approach on a concrete application

Generic Model Refactorings

3 refactorings (Encapsulate Field, Move Method, and Pull Up

Method)

3 different metamodels (Java, MOF, and UML)

Page 23: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Conclusion

Approach for generic model refactorings

Model typing and weaving of aspects

Writing adaptations can be more or less difficult

Once adaptation done, one can reuse all transfo

If new transfo added, it can be applied on all target metamodels

Flexible reuse of model transformations

Generalisable to other endogenous MTs

Generic Model Refactorings

Page 24: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Conclusion

AOM perspective : “Weaving refactoring aspects into

metamodels”

Future Work

Increase the repository of refactorings on other metamodels

Experiment on large scale applications such as Java programs

Experiment with other model transformations

Generic Model Refactorings

Page 25: Generic Model Refactorings - Colorado State University · Generic Model Refactorings Naouel Moha, Vincent Mahé, Olivier Barais, and Jean-Marc Jézéquel Triskell Team, INRIA Rennes

Moha ©

Questions

Contact: [email protected]

http://www.irisa.fr/triskell