[Acceleo] Using ecore types in generation modules [message #1006656] |
Fri, 01 February 2013 10:40 |
Colin Powaa 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 |
Ed Willink 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.02445 seconds