-- $Id$ module AsyncMethods; create OUT : UML refining IN : UML; -- ====================================================================== -- model-specific helpers begin -- ====================================================================== helper context UML!ProcedureExpression def : method() : UML!Method = UML!Method.allInstances()->select(m|m.body=self)->first(); helper context UML!Operation def : isAsynchronous() : Boolean = not self.stereotype->select(s|s.name='asynchronous')->isEmpty(); helper context String def : asynchronous() : String = 'Thread t = new Thread() {\n' + ' public void run() {\n' + self + '\n' + ' }\n' + '};\n' + 't.start();'; -- ====================================================================== -- model-specific helpers end -- ====================================================================== -- ====================================================================== -- transformation rules begin -- ====================================================================== rule ProcedureExpression { from s : UML!ProcedureExpression (not s.method().specification.isAsynchronous()) to t : UML!ProcedureExpression mapsTo s ( body <- s.body, language <- s.language) } rule AsyncProcedureExpression { from s : UML!ProcedureExpression ( s.method().specification.isAsynchronous()) to t : UML!ProcedureExpression mapsTo s ( body <- s.body.asynchronous(), language <- s.language) } rule Model { from s : UML!Model to t : UML!Model mapsTo s ( isLeaf <- s.isLeaf, isRoot <- s.isRoot, visibility <- s.visibility, name <- s.name, isSpecification <- s.isSpecification, isAbstract <- s.isAbstract, templateParameter <- s.templateParameter, elementImport <- s.elementImport, comment <- s.comment, ownedElement <- s.ownedElement, taggedValue <- s.taggedValue, clientDependency <- s.clientDependency, constraint <- s.constraint, targetFlow <- s.targetFlow, generalization <- s.generalization, stereotype <- s.stereotype, sourceFlow <- s.sourceFlow) } -- ====================================================================== -- transformation rules end -- ======================================================================