I am dealing with one problem, i want to define a recursive helper Method
For example if i have a class "Group" and a class called "Entity" an an abstract class "Thing" (Thing is the superclass of Group and Entity)
So a Group can contain Entities and other Groups
this is a possible hierarchy
Has anyone an idea how i can define a recursive helper with which i can retrieve all the "Entity" elements in this hierarchy, and i just commit a Sequence(MMModel!Thing) which is containing the the two Elements on the root level (in this case the first Entity and the first group from the possible hierarchy)
This doesn't look difficult at all. You just need to have two variants of the helper. One for Group and one for Entity. The Entity version does return a Sequence only containing self. The Group version collects all from its elements and flattens it.
This might not be strictly correct code, but it should get you the idea:
Thx. I have now managed to create an revursive helper
But i have one Problem in the else part. want to store the Sequence elements with the new appended Element in an helper variable.
unfortunately this does not work
helper def: fields: Sequence(FileDefinition!FieldDefinition) =
helper context GradingSystem!TaskGroup def : getConcreteTasks() : Sequence(FileDefinition!FieldDefinition ) =
self.contains->iterate( child ; elements : Sequence(FileDefinition!FieldDefinition ) =
if child.oclIsTypeOf(GradingSystem!TaskGroup) then
)-- TaskGroup : recursive call
thisModule.fields.union((elements.append(thisModule.NewStaticField(self.name+child.name+'Points', 'Integer'))) )
-- cant store the actual elements sequence in the helper fields, thisModule.field always stays empty
any other possibilities to store this?
) -- ConcreteTask
) -> append(thisModule.NewAgreggField(self.name,'Integer',thisModule.fields )) -- here i would need the thisModule.fields
union creates a new instance of a sequence and doesn't modify it. So you would need to assign a value to thisModule.fields. However you only could do that in an imperative do-block. You should use the let-expression in that helper to have a variable that you would now use the thisModule.fields is used for. Globals should be avoided in ATL as much as possible.