Skip to main content



      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 00:08 Go to next message
Eclipse UserFriend
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 00:10] by Moderator

Re: Populate method in Template: Not working as expected [message #1750669 is a reply to message #1750658] Sat, 24 December 2016 06:37 Go to previous messageGo to next message
Eclipse UserFriend
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 13:59 Go to previous message
Eclipse UserFriend
Thanks, Dimitris. It works!
Previous Topic:Global variables in EGL
Next Topic:Derived attributes - emphatic
Goto Forum:
  


Current Time: Wed Jul 23 23:37:08 EDT 2025

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

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

Back to the top