-- $Id$ module AssociationAttributes; create OUT : UML refining IN : UML, MERGE : UML; uses Java; uses MergeHelpers; -- ====================================================================== -- -- Begin model merging section -- -- ====================================================================== -- From: MergeModel.atl 3150 2006-01-16 13:32:57Z dwagelaa -- ====================================================================== -- merge helper variables begin -- ====================================================================== helper def : inElements : Set(UML!Element) = UML!Element.allInstancesFrom('IN'); helper def : mergeElements : Set(UML!Element) = UML!Element.allInstancesFrom('MERGE'); helper def : newElements : Sequence(UML!Element) = Sequence{ UML!Classifier.allInstancesFrom('MERGE')->select(c|c.notInSourceModel()), UML!Package.allInstancesFrom('MERGE')->select(p|p.notInSourceModel()), UML!TagDefinition.allInstancesFrom('MERGE')->select(t|t.notInSourceModel()), UML!Stereotype.allInstancesFrom('MERGE')->select(s|s.notInSourceModel()), UML!Association.allInstancesFrom('MERGE')->select(a|a.notInSourceModel()), UML!Dependency.allInstancesFrom('MERGE')->select(d|d.notInSourceModel()), UML!Generalization.allInstancesFrom('MERGE')->select(g|g.notInSourceModel()) }->flatten(); -- ====================================================================== -- merge helper variables end -- ====================================================================== -- ====================================================================== -- model merge begin -- ====================================================================== rule MergeAssociation { from s : UML!Association ( if thisModule.newElements->includes(s) then s.oclIsTypeOf(UML!Association) else false endif) to t : UML!Association mapsTo s ( isRoot <- s.isRoot, isAbstract <- s.isAbstract, visibility <- s.visibility, name <- s.name, isSpecification <- s.isSpecification, isLeaf <- s.isLeaf, comment <- s.comment, constraint <- s.constraint, stereotype <- s.stereotype->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif), namespace <- if thisModule.newElements->includes(s.namespace) then s.namespace else s.namespace.fromSourceModel() endif) } rule MergeTaggedValue { from s : UML!TaggedValue ( if thisModule.mergeElements->includes(s) then s.notInSourceModel() else false endif) to t : UML!TaggedValue mapsTo s ( dataValue <- s.dataValue, visibility <- s.visibility, name <- s.name, isSpecification <- s.isSpecification, referenceValue <- s.referenceValue, modelElement <- s.modelElement, comment <- s.comment, constraint <- s.constraint, stereotype <- s.stereotype->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif), clientDependency <- s.clientDependency, type <- if thisModule.newElements->includes(s.type) then s.type else s.type.fromSourceModel() endif) } rule MergeOperation { from s : UML!Operation ( if thisModule.mergeElements->includes(s) then s.notInSourceModel() else false endif) to t : UML!Operation mapsTo s ( owner <- if thisModule.newElements->includes(s.owner) then s.owner else s.owner.fromSourceModel() endif, parameter <- s.parameter, ownerScope <- s.ownerScope, visibility <- s.visibility, isQuery <- s.isQuery, isAbstract <- s.isAbstract, concurrency <- s.concurrency, name <- s.name, isSpecification <- s.isSpecification, isRoot <- s.isRoot, isLeaf <- s.isLeaf, specification <- s.specification, comment <- s.comment, constraint <- s.constraint, stereotype <- s.stereotype->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif)) } rule MergeAbstraction { from s : UML!Abstraction ( thisModule.newElements->includes(s)) to t : UML!Abstraction mapsTo s ( mapping <- s.mapping, visibility <- s.visibility, name <- s.name, isSpecification <- s.isSpecification, comment <- s.comment, client <- s.client->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif), constraint <- s.constraint, stereotype <- s.stereotype->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif), supplier <- s.supplier->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif), namespace <- if thisModule.newElements->includes(s.namespace) then s.namespace else s.namespace.fromSourceModel() endif) } rule MergeParameter { from s : UML!Parameter ( if thisModule.mergeElements->includes(s) then s.notInSourceModel() else false endif) to t : UML!Parameter mapsTo s ( kind <- s.kind, visibility <- s.visibility, name <- s.name, isSpecification <- s.isSpecification, defaultValue <- s.defaultValue, comment <- s.comment, type <- if thisModule.newElements->includes(s.type) then s.type else s.type.fromSourceModel() endif, constraint <- s.constraint, stereotype <- s.stereotype->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif)) } rule MergeClass { from s : UML!Class ( if thisModule.newElements->includes(s) then s.oclIsTypeOf(UML!Class) else false endif) to t : UML!Class mapsTo s ( isRoot <- s.isRoot, isActive <- s.isActive, isAbstract <- s.isAbstract, visibility <- s.visibility, name <- s.name, isSpecification <- s.isSpecification, isLeaf <- s.isLeaf, comment <- s.comment, constraint <- s.constraint, stereotype <- s.stereotype->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif), namespace <- if thisModule.newElements->includes(s.namespace) then s.namespace else s.namespace.fromSourceModel() endif) } rule MergeInterface { from s : UML!Interface ( thisModule.newElements->includes(s)) to t : UML!Interface mapsTo s ( isRoot <- s.isRoot, isAbstract <- s.isAbstract, visibility <- s.visibility, name <- s.name, isSpecification <- s.isSpecification, isLeaf <- s.isLeaf, comment <- s.comment, constraint <- s.constraint, stereotype <- s.stereotype->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif), namespace <- if thisModule.newElements->includes(s.namespace) then s.namespace else s.namespace.fromSourceModel() endif) } rule MergeDataType { from s : UML!DataType ( if thisModule.newElements->includes(s) then s.oclIsTypeOf(UML!DataType) else false endif) to t : UML!DataType mapsTo s ( isRoot <- s.isRoot, isAbstract <- s.isAbstract, visibility <- s.visibility, name <- s.name, isSpecification <- s.isSpecification, isLeaf <- s.isLeaf, comment <- s.comment, constraint <- s.constraint, stereotype <- s.stereotype->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif), namespace <- if thisModule.newElements->includes(s.namespace) then s.namespace else s.namespace.fromSourceModel() endif) } rule MergeComponent { from s : UML!Component( thisModule.newElements->includes(s)) to t : UML!Component mapsTo s ( isSpecification <- s.isSpecification, visibility <- s.visibility, name <- s.name, isAbstract <- s.isAbstract, isLeaf <- s.isLeaf, isRoot <- s.isRoot, constraint <- s.constraint, comment <- s.comment, stereotype <- s.stereotype->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif), namespace <- if thisModule.newElements->includes(s.namespace) then s.namespace else s.namespace.fromSourceModel() endif) } rule MergePackage { from s : UML!Package ( if thisModule.newElements->includes(s) then s.oclIsTypeOf(UML!Package) else false endif) to t : UML!Package mapsTo s ( isRoot <- s.isRoot, isAbstract <- s.isAbstract, visibility <- s.visibility, name <- s.name, isSpecification <- s.isSpecification, isLeaf <- s.isLeaf, comment <- s.comment, constraint <- s.constraint, stereotype <- s.stereotype->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif), namespace <- if thisModule.newElements->includes(s.namespace) then s.namespace else s.namespace.fromSourceModel() endif) } rule MergeAssociationEnd { from s : UML!AssociationEnd ( if thisModule.mergeElements->includes(s) then if s.oclIsTypeOf(UML!AssociationEnd) then s.notInSourceModel() else false endif else false endif) to t : UML!AssociationEnd mapsTo s ( association <- s.association, targetScope <- s.targetScope, isNavigable <- s.isNavigable, ordering <- s.ordering, changeability <- s.changeability, multiplicity <- s.multiplicity, aggregation <- s.aggregation, visibility <- s.visibility, name <- s.name, isSpecification <- s.isSpecification, qualifier <- s.qualifier, participant <- if thisModule.newElements->includes(s.participant) then s.participant else s.participant.fromSourceModel() endif, comment <- s.comment, constraint <- s.constraint, specification <- s.specification->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif), stereotype <- s.stereotype->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif)) } rule MergeAttribute { from s : UML!Attribute ( if thisModule.mergeElements->includes(s) then s.notInSourceModel() else false endif) to t : UML!Attribute mapsTo s ( owner <- if thisModule.newElements->includes(s.owner) then s.owner else s.owner.fromSourceModel() endif, targetScope <- s.targetScope, initialValue <- s.initialValue, ownerScope <- s.ownerScope, visibility <- s.visibility, changeability <- s.changeability, ordering <- s.ordering, name <- s.name, isSpecification <- s.isSpecification, multiplicity <- s.multiplicity, comment <- s.comment, constraint <- s.constraint, stereotype <- s.stereotype->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif), type <- if thisModule.newElements->includes(s.type) then s.type else s.type.fromSourceModel() endif) } rule MergeGeneralization { from s : UML!Generalization ( thisModule.newElements->includes(s)) to t : UML!Generalization mapsTo s ( discriminator <- s.discriminator, visibility <- s.visibility, name <- s.name, isSpecification <- s.isSpecification, templateParameter <- s.templateParameter, comment <- s.comment, powertype <- if s.powertype.oclIsUndefined() then s.powertype else if thisModule.newElements->includes(s.powertype) then s.powertype else s.powertype.fromSourceModel() endif endif, parent <- if thisModule.newElements->includes(s.parent) then s.parent else s.parent.fromSourceModel() endif, constraint <- s.constraint, stereotype <- s.stereotype->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif), child <- if thisModule.newElements->includes(s.child) then s.child else s.child.fromSourceModel() endif, namespace <- if thisModule.newElements->includes(s.namespace) then s.namespace else s.namespace.fromSourceModel() endif) } rule MergeDependency { from s : UML!Dependency ( if thisModule.newElements->includes(s) then s.oclIsTypeOf(UML!Dependency) else false endif) to t : UML!Dependency mapsTo s ( visibility <- s.visibility, name <- s.name, isSpecification <- s.isSpecification, comment <- s.comment, client <- s.client->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif), constraint <- s.constraint, stereotype <- s.stereotype->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif), supplier <- s.supplier->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif), namespace <- if thisModule.newElements->includes(s.namespace) then s.namespace else s.namespace.fromSourceModel() endif) } rule MergeTagDefinition { from s : UML!TagDefinition ( thisModule.newElements->includes(s)) to t : UML!TagDefinition mapsTo s ( owner <- if thisModule.newElements->includes(s.owner) then s.owner else s.owner.fromSourceModel() endif, tagType <- s.tagType, multiplicity <- s.multiplicity, visibility <- s.visibility, name <- s.name, isSpecification <- s.isSpecification, templateParameter <- s.templateParameter, comment <- s.comment, constraint <- s.constraint, stereotype <- s.stereotype->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif), namespace <- if thisModule.newElements->includes(s.namespace) then s.namespace else s.namespace.fromSourceModel() endif) } rule MergeStereotype { from s : UML!Stereotype ( thisModule.newElements->includes(s)) to t : UML!Stereotype mapsTo s ( isRoot <- s.isRoot, isAbstract <- s.isAbstract, baseClass <- s.baseClass, visibility <- s.visibility, name <- s.name, icon <- s.icon, isSpecification <- s.isSpecification, isLeaf <- s.isLeaf, comment <- s.comment, constraint <- s.constraint, stereotype <- s.stereotype->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif), stereotypeConstraint <- s.stereotypeConstraint, namespace <- if thisModule.newElements->includes(s.namespace) then s.namespace else s.namespace.fromSourceModel() endif) } rule MergeMethod { from s : UML!Method ( if thisModule.mergeElements->includes(s) then s.notInSourceModel() else false endif) to t : UML!Method mapsTo s ( owner <- if thisModule.newElements->includes(s.owner) then s.owner else s.owner.fromSourceModel() endif, body <- s.body, ownerScope <- s.ownerScope, visibility <- s.visibility, isQuery <- s.isQuery, name <- s.name, isSpecification <- s.isSpecification, comment <- s.comment, specification <- s.specification, constraint <- s.constraint, stereotype <- s.stereotype->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif)) } rule MergeException { from s : UML!Exception ( thisModule.newElements->includes(s)) to t : UML!Exception mapsTo s ( isRoot <- s.isRoot, name <- s.name, isAbstract <- s.isAbstract, visibility <- s.visibility, isSpecification <- s.isSpecification, isLeaf <- s.isLeaf, "context" <- s."context"->collect(e|if e.notInSourceModel() then e else e.fromSourceModel() endif), constraint <- s.constraint, stereotype <- s.stereotype->collect(e|if thisModule.newElements->includes(e) then e else e.fromSourceModel() endif), comment <- s.comment, namespace <- if thisModule.newElements->includes(s.namespace) then s.namespace else s.namespace.fromSourceModel() endif) } -- ====================================================================== -- model merge end -- ====================================================================== -- ====================================================================== -- -- End model merging section -- -- ====================================================================== -- ====================================================================== -- model-specific helpers begin -- ====================================================================== helper def : oclCollection : UML!DataType = 'Collection'.dataType(); helper def : oclSequence : UML!DataType = 'Sequence'.dataType(); helper context String def : dataType() : UML!DataType = UML!DataType.allInstances()->select(c|c.name=self)->select(d| thisModule.inElements->includes(d) or thisModule.newElements->includes(d))->first(); helper context UML!AssociationEnd def : navigableFrom() : UML!Classifier = self.association.connection->select(x|x<>self)->first().participant; helper context UML!AssociationEnd def : isSingle() : Boolean = self.multiplicity.range->select(r|r.upper<>1)->isEmpty(); helper context UML!AssociationEnd def : type() : UML!Classifier = if self.isSingle() then self.participant else if self.ordering = #ok_ordered then thisModule.oclSequence else thisModule.oclCollection endif endif; helper context UML!ModelElement def : hasTaggedValue(type : String) : Boolean = self.taggedValue->select(v|v.type.name=type)->notEmpty(); helper context UML!ModelElement def : taggedValue(type : String) : UML!TaggedValue = self.taggedValue->select(v|v.type.name=type)->first(); helper context UML!AssociationEnd def : instance() : String = if self.hasTaggedValue('gentleware-initialValue') then self.taggedValue('gentleware-initialValue').dataValue->asSequence()->first() else self.type().name.javaInstance() endif; -- ====================================================================== -- model-specific helpers end -- ====================================================================== -- ====================================================================== -- transformations rules begin -- ====================================================================== rule AssociationEndAttribute { from s : UML!AssociationEnd ( if thisModule.inElements->includes(s) then s.oclIsTypeOf(UML!AssociationEnd) and s.isNavigable and s.navigableFrom().oclIsKindOf(UML!Class) else false endif) to t : UML!AssociationEnd mapsTo s ( association <- s.association, multiplicity <- s.multiplicity, aggregation <- s.aggregation, visibility <- s.visibility, targetScope <- s.targetScope, changeability <- s.changeability, name <- s.name, isSpecification <- s.isSpecification, ordering <- s.ordering, isNavigable <- s.isNavigable, templateParameter <- s.templateParameter, comment <- s.comment, qualifier <- s.qualifier, taggedValue <- s.taggedValue, clientDependency <- s.clientDependency, specification <- s.specification, constraint <- s.constraint, targetFlow <- s.targetFlow, stereotype <- s.stereotype, participant <- s.participant, sourceFlow <- s.sourceFlow), a : UML!Attribute ( name <- s.name, owner <- s.navigableFrom(), type <- s.type(), visibility <- s.visibility, ownerScope <- s.targetScope, changeability <- s.changeability, initialValue <- v), v : UML!Expression ( language <- 'java', body <- s.instance()) } rule AssociationEnd { from s : UML!AssociationEnd ( if thisModule.inElements->includes(s) then s.oclIsTypeOf(UML!AssociationEnd) and not (s.isNavigable and s.navigableFrom().oclIsKindOf(UML!Class)) else false endif) to t : UML!AssociationEnd mapsTo s ( association <- s.association, multiplicity <- s.multiplicity, aggregation <- s.aggregation, visibility <- s.visibility, targetScope <- s.targetScope, changeability <- s.changeability, name <- s.name, isSpecification <- s.isSpecification, ordering <- s.ordering, isNavigable <- s.isNavigable, templateParameter <- s.templateParameter, comment <- s.comment, qualifier <- s.qualifier, taggedValue <- s.taggedValue, clientDependency <- s.clientDependency, specification <- s.specification, constraint <- s.constraint, targetFlow <- s.targetFlow, stereotype <- s.stereotype, participant <- s.participant, sourceFlow <- s.sourceFlow) } -- ====================================================================== -- transformation rules end -- ======================================================================