Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » 2 models to model transformation
2 models to model transformation [message #1735635] Tue, 21 June 2016 14:09 Go to next message
Marcos Neto is currently offline Marcos NetoFriend
Messages: 2
Registered: June 2016
Junior Member
Hi everyone,

someone has an example of transformation merging 2 ecore classes into a new one, joining subclasses?

Att
Re: 2 models to model transformation [message #1735807 is a reply to message #1735635] Wed, 22 June 2016 20:59 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 350
Registered: September 2012
Location: Belgium
Senior Member

I understand you want to migrate all references from the source ecore classes to the merged ecore class? ATL only supports reference migration scenarios in EMFTVM using the "remap()" operation in refining mode:
-- @atlcompiler emftvm
-- @nsURI ECORE=http://www.eclipse.org/emf/2002/Ecore
module MergeEClass;
create OUT: ECORE refining IN: ECORE;

rule Package {
	from
		s : ECORE!EPackage
	to
		t : ECORE!EPackage (
			-- remap() will replace 'dropped' by 'retained', so 'retained' is excluded to prevent duplicates
			eClassifiers <- s.eClassifiers -> 
					excluding(s.eClassifiers -> any(c | c.name = 'Retained'))
		)
}

rule MergeClass {
	from
		retainedClass: ECORE!EClass,
		droppedClass: ECORE!EClass (
			retainedClass.name = 'Retained' and 
			droppedClass.name = 'Dropped'
	)
	to
		t : ECORE!EClass mapsTo retainedClass (
			eSuperTypes <- droppedClass.remap(retainedClass).eSuperTypes ->
					asOrderedSet() -> union(droppedClass.eSuperTypes -> asOrderedSet())
		)
}

rule DeleteGenericType {
	from
		s : ECORE!EGenericType (
			let c : OclAny = s.refImmediateComposite() in
			c.oclIsKindOf(ECORE!EClass) and c.name = 'Dropped'
		)
}


Separate rules 'Package' and 'DeleteGenericType' are required to deal with quirks in the Ecore metamodel implementation (EPackage.eClassifiers must be unique, and each EClass has implicit EGenericType instances for each of its superclass references). Attached you'll find an example Eclipse project.


Cheers,
Dennis
Re: 2 models to model transformation [message #1736924 is a reply to message #1735807] Mon, 04 July 2016 11:54 Go to previous message
Marcos Neto is currently offline Marcos NetoFriend
Messages: 2
Registered: June 2016
Junior Member
Hi Dennis, thanks for your response.

No, I don't want to migrate the references, I want to create a new model with the union of two other classes, including subclasses, attributes, etc.

e.g.:

Class CarA with attributes
- year(int)
- chassi(int)

Subclass Motor from CarA with attributes
- potency(int)

Class CarB with attributes:
- year(int)
- chassi(int)

Subclass Motor from CarB with attributes
- potency(int)

Subclass Door from CarB with attributes
- position(int)

The new class that I want to generate is the merge of class CarA with CarB
Class MergeClassACarB with attributes:
- year(int)
- chassi(int)

Subclass Motor
- potency(int)

Subclass Door
- position(int)


I really need any example code for this.

Att,

Previous Topic:Problem with simple ATL transformation
Next Topic:UML primitive types
Goto Forum:
  


Current Time: Sun Sep 24 19:39:42 GMT 2017

Powered by FUDForum. Page generated in 0.02559 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software