Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Populate method in Template: Not working as expected(EGL)
Populate method in Template: Not working as expected [message #1750658] Sat, 24 December 2016 05:08 Go to next message
John Dawes is currently offline John DawesFriend
Messages: 19
Registered: November 2016
Junior Member
Hi,

Please find my code below.

var template:Template = TemplateFactory.load("body.egl");

for(class:Mine!Class in Class.allInstances) {
template.populate("cls", class);
template.generate(class.name + ".java");
}

Here I am calling the 'body.egl' file which has a variable called 'cls'. I was expecting the 'cls' variable to have different values inside the 'body.egl' file depending on the value of the 'class' variable in the for loop. Surprisingly, although it generates files with different names for different loop iterations, for different instances of 'body.egl' content, it only uses the value assigned to it during the first loop iteration. Am I wrong in terms of my expectation? Should I do it differently for making a variable available in the 'body.egl' file?

Thanks

[Updated on: Sat, 24 December 2016 05:10]

Report message to a moderator

Re: Populate method in Template: Not working as expected [message #1750669 is a reply to message #1750658] Sat, 24 December 2016 11:37 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2154
Registered: July 2009
Location: York, UK
Senior Member

Hi John,

Templates are not reusable so to make this work you should move var template:Template ... into the for loop. Alternatively, you may want to consider using EGX, which provides a more elegant syntax to orchestrate the execution of your templates [1].

Cheers,
Dimitris

[1] https://www.eclipse.org/epsilon/doc/articles/code-generation-tutorial-egl/
icon14.gif  Re: Populate method in Template: Not working as expected [message #1750675 is a reply to message #1750669] Sat, 24 December 2016 18:59 Go to previous message
John Dawes is currently offline John DawesFriend
Messages: 19
Registered: November 2016
Junior Member
Thanks, Dimitris. It works!
Previous Topic:Global variables in EGL
Next Topic:Derived attributes - emphatic
Goto Forum:
  


Current Time: Fri Mar 29 15:21:01 GMT 2024

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

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

Back to the top