Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Class inheritance and recursivity
[Acceleo] Class inheritance and recursivity [message #649684] Thu, 20 January 2011 05:03 Go to next message
Charlie Mordant is currently offline Charlie Mordant
Messages: 68
Registered: July 2010
Member

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 #649709 is a reply to message #649684] Thu, 20 January 2011 07:08 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane Begaudeau
Messages: 406
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi Charlie,

I'm not sure that I understood your problem, I don't get this part: "I wanted to have a set containing [Human, User] from the Player class, the same for a nineth degrees inheritance."

Could you show us a small template with comments explaining what you would expect from the generation.

Thanks.

Stephane Begaudeau, Obeo



Re: [Acceleo] Class inheritance and recursivity [message #649716 is a reply to message #649709] Thu, 20 January 2011 07:19 Go to previous messageGo to next message
Charlie Mordant is currently offline Charlie Mordant
Messages: 68
Registered: July 2010
Member

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 #649734 is a reply to message #649716] Thu, 20 January 2011 08:16 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1609
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050409050705070005000705
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Charlie,

You'll have to know how to go up in your class hierarchy, and do this
either :
- Through an OCL "iterate
- recursively through Acceleo
- Through a Java Service

For example, with recursive queries (and assuming you can retrieve the
super classes through "eSuperTypes") :

[query public getSuperClasses(c : EClass) : Sequence(EClass) = if
c.eSuperTypes->size() = 0 then c.eSuperTypes else
c.eSuperTypes->asSequence()->union(c.eSuperTypes.getSuperClasses()- >flatten())
endif/]

Laurent Goubet
Obeo

On 20/01/2011 13:19, Charlie Mordant wrote:
> 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>
>
> 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]
>


--------------050409050705070005000705
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------050409050705070005000705--
Re: [Acceleo] Class inheritance and recursivity [message #649745 is a reply to message #649684] Thu, 20 January 2011 09:10 Go to previous message
Charlie Mordant is currently offline Charlie Mordant
Messages: 68
Registered: July 2010
Member

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
Previous Topic:[Xtend] Model modification of a UML model using a profile
Next Topic:[XPand] strange failure (no viable alternative at input)
Goto Forum:
  


Current Time: Thu Apr 17 11:46:04 EDT 2014

Powered by FUDForum. Page generated in 0.16961 seconds