Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Using ecore types in generation modules
[Acceleo] Using ecore types in generation modules [message #1006656] Fri, 01 February 2013 10:40 Go to next message
Colin PowaaFriend
Messages: 5
Registered: December 2011
Junior Member
Hello,

I am faced to a wall for a week with that issue, but I am sure there is a way to make it work somehow. I would like to make a generic table generation template. The aim is to get an html table for each object of my model. The first row contains the name of an attribute and the second one contains the value. Here is my first try :

[template public generateTable(object : NamedElement)]
[if ((object.name <> null) and (object.name <> ''))]
<h2 id="[object.eClass().name/]_[object.name/]">[object.name/]</h2>
<table>	
[for (feature : EStrucuralFeature| object.eClass().eAllStructuralFeatures)]
	<tr>
		<td>[feature.oclAsType(EStructuralFeature).name/]</td>
		<td>[object.eGet(feature.oclAsType(EStructuralFeature).name)/]</td>
	</tr>
[/for]
</table>
[/if]


My problem concerns the type of the object feature in the for loop. My template does not recognize the type EStructuralFeature, and OclAny does not work either.

This following code works anyway for the first row, but I do not know a way to access the variable inside a for loop when using the short way : (the variable 'this' does not exist)

[for (object.eClass().eAllStructuralFeatures)]
	<tr>
		<td>[oclAsType(EStructuralFeature).name/]</td>
		<td>[object.eGet(this.oclAsType(EStructuralFeature).name)/]</td>
	</tr>
[/for]


Would anybody know a way, either to use the ecore type EStrucutralFeature in my template, or to access the variable when using the short way of defining the loop ?

Thanks in advance,

Colin
Re: [Acceleo] Using ecore types in generation modules [message #1006670 is a reply to message #1006656] Fri, 01 February 2013 11:28 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

If you specify 'http://www.eclipse.org/emf/2002/Ecore' as (one of) your
metamodels on the {Module line it should all work fine.

But since your example has "NamedElement" perhaps you are using UML, and
"EStrucuralFeature" perhaps you are not showing us the real problem.

Regards

Ed Willink

On 01/02/2013 10:40, Colin Powaa wrote:
> Hello,
>
> I am faced to a wall for a week with that issue, but I am sure there
> is a way to make it work somehow. I would like to make a generic table
> generation template. The aim is to get an html table for each object
> of my model. The first row contains the name of an attribute and the
> second one contains the value. Here is my first try :
>
>
> [template public generateTable(object : NamedElement)]
> [if ((object.name <> null) and (object.name <> ''))]
> <h2 id="[object.eClass().name/]_[object.name/]">[object.name/]</h2>
> <table>
> [for (feature : EStrucuralFeature|
> object.eClass().eAllStructuralFeatures)]
> <tr>
> <td>[feature.oclAsType(EStructuralFeature).name/]</td>
> <td>[object.eGet(feature.oclAsType(EStructuralFeature).name)/]</td>
> </tr>
> [/for]
> </table>
> [/if]
>
>
> My problem concerns the type of the object feature in the for loop. My
> template does not recognize the type EStructuralFeature, and OclAny
> does not work either.
>
> This following code works anyway for the first row, but I do not know
> a way to access the variable inside a for loop when using the short
> way : (the variable 'this' does not exist)
>
>
> [for (object.eClass().eAllStructuralFeatures)]
> <tr>
> <td>[oclAsType(EStructuralFeature).name/]</td>
> <td>[object.eGet(this.oclAsType(EStructuralFeature).name)/]</td>
> </tr>
> [/for]
>
>
> Would anybody know a way, either to use the ecore type
> EStrucutralFeature in my template, or to access the variable when
> using the short way of defining the loop ?
>
> Thanks in advance,
>
> Colin
Re: [Acceleo] Using ecore types in generation modules [message #1006707 is a reply to message #1006670] Fri, 01 February 2013 13:58 Go to previous message
Colin PowaaFriend
Messages: 5
Registered: December 2011
Junior Member
Hello Ed,

Thank you for your answer, it works perfectly. I did not know it was possible to use several metamodel in a single template.
The class NamedElement is defined in my metamodel. I use to define it as mother of all other classes systematically.

Best Regards,

Colin
Previous Topic:[Acceleo/Papyrus]How to view Acceleo UML2Java example with Papyrus?
Next Topic:XPand
Goto Forum:
  


Current Time: Sat Apr 20 02:27:20 GMT 2024

Powered by FUDForum. Page generated in 0.02445 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top