Skip to main content



      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 04:39 Go to next message
Eclipse UserFriend
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 13:39 Go to previous messageGo to next message
Eclipse UserFriend
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 04:41 Go to previous messageGo to next message
Eclipse UserFriend
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 05:05] by Moderator

Re: [Xpand] Call Template for Null Object [message #644274 is a reply to message #644258] Fri, 10 December 2010 05:34 Go to previous message
Eclipse UserFriend
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: Sun Jul 06 10:07:25 EDT 2025

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

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

Back to the top