| [Acceleo] Class inheritance and recursivity [message #649684] |
Thu, 20 January 2011 05:03  |
|
Hi,
I'm trying to make an Acceleo template but I'm stuck at one point:
I'm not able to know which are the entire superclasses stack of the Class I'm generating.
Let's take an example:
Human<-User<-Player.
I wanted to have a set containing [Human, User] from the Player class, the same for a nineth degrees inheritance.
I don't see how can I do that without variable declaration.
Thanks in advance, Tcharl
|
|
|
|
| Re: [Acceleo] Class inheritance and recursivity [message #649716 is a reply to message #649709] |
Thu, 20 January 2011 07:19   |
|
I'll try so,
Let's have a Human (abstract) with a name and a surname.
Let's have a User (abstract) that extends Human with an email & pwd.
Let's have a Player with his poker stack.
I'm trying to generate a flex datagrid containing columns name/surname/email/pwd/stack.
[template public AllDataFromAConcreteClass(c : Class)]
[if(not(c.isAbstract()]
<mx:DataGrid x="27" y="26" dataProvider="{model.all[c.name/]}" >
<mx:columns>
[comment]
this class attribute
[/comment]
[for (p: Property |c.attribute)]
<mx:DataGridColumn headerText="[p.name/]"
dataField="[p.name/]"/>
[/for]
[for(superC : Class | c.getAllAbstractSuperclassStackThatIDontKnowHowToDo())]
[for (p: Property |superC.attribute)]
<mx:DataGridColumn headerText="[p.name/]"
dataField="[p.name/]"/>
[/for]
[/for]
</mx:columns>
</mx:DataGrid>
[/if]
[/template]
Something like c.inheritedMember but for Class elements
[Updated on: Thu, 20 January 2011 08:20] Report message to a moderator
|
|
|
|
| Re: [Acceleo] Class inheritance and recursivity [message #649745 is a reply to message #649684] |
Thu, 20 January 2011 09:10  |
|
Thanks Laurent,
I'm such a brainless programmer, recursivity is very easy and I could have guessed it without help.
Here is the acceleo version of the query:
[query public findSuperClassStack(c : Class) : Set(Class) =
if(c.superClass->size() = 0) then c.superClass else c.superClass->asSet()->union(c.superClass.findSuperClassStack()->flatten()->asSet()) endif /]
regards, Charlie
|
|
|
Powered by
FUDForum. Page generated in 0.04400 seconds