-- $Id$ query ModelCopyGenerator = MOF14!Class.allInstances()->iterate(e; acc : String = '-- Generated by: $Id$\n' + 'module ModelCopy;\n\n' + 'create OUT : OUTMODEL from IN : INMODEL;\n\n'| acc + e.toRuleString()). writeTo('ModelCopy.atl'.path()); uses Config; helper context MOF14!ModelElement def : qName() : String = if self.container.oclIsTypeOf(MOF14!Package) then self.container.qName() + '::' + self.name else self.name endif; helper context MOF14!ModelElement def : cname() : String = if self.useQualifiedName() then self.qName() else self.name endif; helper context MOF14!Class def : toRuleString() : String = if not self.isAbstract and self.inclusionCondition() then 'rule ' + self.cname() + ' {\n' + ' from s : INMODEL!' + self.cname() + self.inputConstraint() + '\n' + ' to t : OUTMODEL!' + self.cname() + ' mapsTo s (' + self.contentsToString() + ')\n' + '}\n\n' else '' endif; helper context MOF14!GeneralizableElement def : inputConstraint() : String = if self.hasConcreteSubclasses() then ' (s.oclIsTypeOf(INMODEL!' + self.cname() + '))' else '' endif; helper context MOF14!GeneralizableElement def : hasConcreteSubclasses() : Boolean = not MOF14!GeneralizableElement.allInstances()->select(e| e.supertypes->includes(self) and not e.isAbstract)->isEmpty(); helper context MOF14!GeneralizableElement def : includesMember(member : MOF14!ModelElement) : Boolean = self.contents->includes(member) or not self.supertypes->select(s|s.includesMember(member))->isEmpty(); helper context MOF14!GeneralizableElement def : contentsToString() : String = self.referencesToString(self.attributesToString('')); helper context MOF14!GeneralizableElement def : attributesToString(head : String) : String = self.featuresToString(head, MOF14!Attribute.allInstances()); helper context MOF14!GeneralizableElement def : referencesToString(head : String) : String = self.featuresToString(head, MOF14!Reference.allInstances()-> select(r|r.referencedEnd.aggregation=#none)); helper context MOF14!GeneralizableElement def : featuresToString(head : String, feature : Sequence(MOF14!StructuralFeature)) : String = feature->select(f|self.includesMember(f))->iterate(e; acc : String = head | if acc.size() = 0 then '\n' + e.toString() else acc + ',\n' + e.toString() endif); helper context MOF14!ModelElement def : toAssignString() : String = if self.name.isKeyword() then ' "' + self.name + '" <- s."' + self.name + '"' else ' ' + self.name + ' <- s.' + self.name endif; helper context MOF14!Attribute def : toString() : String = self.toAssignString(); helper context MOF14!Reference def : toString() : String = self.toAssignString(); helper context String def : isKeyword() : Boolean = Set{'module', 'create', 'from', 'rule', 'to', 'using', 'helper', 'context', 'def', 'and', 'or', 'not', 'if', 'then', 'else', 'endif', 'query', 'library', 'mapsTo', 'String', 'Boolean', 'Integer', 'Real', 'Bag', 'Set', 'OrderedSet', 'Sequence', 'abstract', 'derived', 'refining', 'foreach', 'distinct', 'in', 'do', 'uses', 'let'}->includes(self);