Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo ]ECORE Loop over References
[Acceleo ]ECORE Loop over References [message #791862] Mon, 06 February 2012 10:46 Go to next message
Kalaus Schaefersen is currently offline Kalaus SchaefersenFriend
Messages: 2
Registered: February 2012
Junior Member
Hi,

my M2T templates are based on ECORE and I'd like to write a simple template the copies the values of an object into an array (php). To do so, I need the current index of the for loop. In Acceleo 2.x there was a a current() function, but I could not find anything similar in Acecleo 3.x

My template code looks like:

[for (ref : EReference | e.eReferences)]
$result['['/] X [']'/] = ... // TODO write instead of X the current index
[/for]

The result should look like

$result[0] = ...
$result[1] = ...

This gives me also an warning in the eclipse. Is teher a better way to loop over the refs? For the eAttributes this seems to be fine.

By the way, is there a smarter way to print "[" or "]"s?


THX,

Kalaus

[Updated on: Tue, 07 February 2012 09:00]

Report message to a moderator

Re: [Acceleo ]ECORE Loop over References [message #792678 is a reply to message #791862] Tue, 07 February 2012 09:17 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi,

[for (ref : EReference | e.eReferences)]
Current index: [i/]
[/for]

If you have a compilation issue with this, switch to 3.1.2 (a bug appeared with this in 3.1.1)

Quote:
By the way, is there a smarter way to print "[" or "]"s?

Since '[' is the only character that creates a problem, we choose not to introduce a combination to write it instead of ['['/] and we recommend to use the same for [']'/]

Regards,

Stephane Begaudeau, Obeo

--
Twitter: @sbegaudeau & @acceleo
Google+: stephane.begaudeau & acceleo
Blog: http://stephanebegaudeau.tumblr.com
Acceleo Documentation: http://docs.obeonetwork.com/acceleo
Re: [Acceleo ]ECORE Loop over References [message #808012 is a reply to message #792678] Mon, 27 February 2012 09:45 Go to previous messageGo to next message
Kalaus Schaefersen is currently offline Kalaus SchaefersenFriend
Messages: 2
Registered: February 2012
Junior Member
Hi,

cool this works. But I still stumbled upon one other issue. If I want to loop over all eAttributes and the all eRefrences and write the values into an array, how would I do this the best way? Suppose I don not have an "append" method?

[for (ref : EAttribute | e.eAllAttributes)]
$result['['/] [i/] [']'/] = ... //
[/for]

[for (ref : EReference | e.eReferences)]
$result['['/] X [']'/] = ... // so this should be e.eAllAttributes.size + i or so...
[/for]


Thanks a lot,

Klaus

Re: [Acceleo ]ECORE Loop over References [message #808021 is a reply to message #808012] Mon, 27 February 2012 09:50 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Kalaus,<br>
<br>
Note that you're using eAllAttributes in one case but not e<b>All</b>Reference
in the other so you'll only get the references defined locally in
the class, not the ones from super classes.<br>
<br>
<br>
On 27/02/2012 10:45 AM, Kalaus Schaefersen wrote:
<blockquote cite="mid:jifjbb$25o$1@news.eclipse.org" type="cite">Hi,
<br>
cool this works. But I still stumbled upon one other issue. If I
want to loop over all eAttributes and the all eRefrences and write
the values into an array, how would I do this the best way?
Suppose I don not have an "append" method?
<br>
<br>
[for (ref : EAttribute | e.eAllAttributes)]
<br>
$result['['/] [i/] [']'/] = ... //
<br>
[/for]
<br>
<br>
[for (ref : EReference | e.eReferences)]
<br>
$result['['/] X [']'/] = ... // so this should be
e.eAllAttributes.size + i or so...
<br>
[/for]
<br>
<br>
<br>
Thanks a lot,
<br>
<br>
Klaus
<br>
<br>
<br>
</blockquote>
</body>
</html>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Acceleo ]ECORE Loop over References [message #808930 is a reply to message #791862] Tue, 28 February 2012 09:53 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Kalaus,

Do you really need to iterate through two different loops over attributes and references? You could use a loop on eAllStructuralFeatures instead and not worry about the index.

[for (feature : EStructuralFeature | e.eAllStructuralFeatures())]
$result['['/] [i/] [']'/] = ...
[/for]

Laurent Goubet
Obeo
Previous Topic:[Acceleo] Errors running builder 'Acceleo Builder'
Next Topic:[Acceleo] trying to use eGet
Goto Forum:
  


Current Time: Thu Mar 28 14:01:54 GMT 2024

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

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

Back to the top