Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xpand] Call Template for Null Object
[Xpand] Call Template for Null Object [message #644053] Thu, 09 December 2010 09:39 Go to next message
Gerd Kainz is currently offline Gerd KainzFriend
Messages: 23
Registered: May 2010
Junior Member
Hello everybody,

sometimes it is useful to call an Xpand template like a function. Thereby all information is handed to the template through the parameter list without any concrete object (null) for which the template is called.

Template template.xpt
«DEFINE generate(String content) FOR Void»
    «FILE "Test.txt" -»
        Content: «content»
    «ENDFILE»
«ENDDEFINE»


Template call from workflow
template::generate('Hello World') FOR null


But since Helios this feature is no longer supported. If you call a template with null there is a check which stops the execution. Is there a specific reason for that? Is it possible to reenable this feature?

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=320475

Best regards
Gerd
Re: [Xpand] Call Template for Null Object [message #644185 is a reply to message #644053] Thu, 09 December 2010 18:39 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Why don't you do

<<DEFINE generate FOR String>>
<<ENDDEFINE>>

and

template::generate FOR 'Hello World'

Sven

Am 12/9/10 10:39 AM, schrieb Gerd Kainz:
> Hello everybody,
>
> sometimes it is useful to call an Xpand template like a function.
> Thereby all information is handed to the template through the parameter
> list without any concrete object (null) for which the template is called.
>
> Template template.xpt
> «DEFINE generate(String content) FOR Void»
> «FILE "Test.txt" -»
> Content: «content»
> «ENDFILE»
> «ENDDEFINE»
>
> Template call from workflow
> template::generate('Hello World') FOR null
>
> But since Helios this feature is no longer supported. If you call a
> template with null there is a check which stops the execution. Is there
> a specific reason for that? Is it possible to reenable this feature?
>
> See https://bugs.eclipse.org/bugs/show_bug.cgi?id=320475
>
> Best regards
> Gerd


--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Re: [Xpand] Call Template for Null Object [message #644258 is a reply to message #644185] Fri, 10 December 2010 09:41 Go to previous messageGo to next message
Gerd Kainz is currently offline Gerd KainzFriend
Messages: 23
Registered: May 2010
Junior Member
Hi Sven,

thanks for your hint. It's working if I handover some useless data instead of null. But than I also need to change the data type from Void to something else. That's just a workaround. It doesn't solve the bug (in my opinion) behind.

Some times it makes sense to call a function (handing over all data as parameters) instead of a method (using one special element as this object).

Is there a special reason for the check against a null object, which breaks the usage of a function like call?

Best regards,
Gerd

[Updated on: Fri, 10 December 2010 10:05]

Report message to a moderator

Re: [Xpand] Call Template for Null Object [message #644274 is a reply to message #644258] Fri, 10 December 2010 10:34 Go to previous message
Gerd Kainz is currently offline Gerd KainzFriend
Messages: 23
Registered: May 2010
Junior Member
Hi,

I recently found another workaround. It's working as expected when I replace
template::generate('Hello World') FOR null

by
template::generate('Hello World') FOREACH {null}


Because in the FOREACH branch of method 'evaluateInternal' of class 'org.eclipse.internal.xpand2.ast.ExpandStatement' in plugin 'org.eclipse.xpand' there doesn't exist the check against null.

Best regards,
Gerd
Previous Topic:[Xpand] Determine the template file on runtime in an EXPAND statement
Next Topic:[Acceleo] Intermittent Bug: Nonsense compiler errors that disappear after file is touched
Goto Forum:
  


Current Time: Fri Dec 06 11:10:48 GMT 2024

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

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

Back to the top