Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Use of template result in Sequence of String
[Acceleo] Use of template result in Sequence of String [message #545350] Wed, 07 July 2010 13:47 Go to next message
Sebastien Roy is currently offline Sebastien RoyFriend
Messages: 51
Registered: November 2009
Member
Hello,

I would like to use template results into a sequence of String. The compilation is Ok but I have an exception at runtime :

...
[generateList(Sequence{aBlock('a'), aBlock('b')})/]
...
[template aBlock(str : String)]
value : [str/]
[/template]
...
[template public generateList(args : Sequence(String))]
[for (it : String | args) before ('(') separator (', ') after (')')]
	[it/]
[/for]
[/template]


The exception is :
org.eclipse.acceleo.engine.AcceleoEvaluationException: Invalid type for iteration at line 0 in Module jpaAnnotations for block for (args) before('(') separator(', ') after(')'). org.eclipse.uml2.uml.internal.impl.PropertyImpl was not an instanceof String.


Is it a bug ?
Is there a workaround to make this kind of code working ?

Regards

Sebastien
Re: [Acceleo] Use of template result in Sequence of String [message #545409 is a reply to message #545350] Wed, 07 July 2010 16:43 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4154
Registered: July 2009
Senior Member
Hi Sebastien

There is a workaround; remove the bug in your code. You have passed a
Property rather than a String in the Sequence(String).

It would be helpful if Acceleo or OCL caught this error more cleanly.

In this case I think OCL has correctly constructed a Sequence(Property),
but the template entry has neglected to do a type check/filter and so it
is the iterator that uncovers the error.

You probably meant the aBlock template to be a query.

Regards

Ed Willink

On 07/07/2010 14:47, Sebastien Roy wrote:
> Hello,
>
> I would like to use template results into a sequence of String. The
> compilation is Ok but I have an exception at runtime :
>
>
> ..
> [generateList(Sequence{aBlock('a'), aBlock('b')})/]
> ..
> [template aBlock(str : String)]
> value : [str/]
> [/template]
> ..
> [template public generateList(args : Sequence(String))]
> [for (it : String | args) before ('(') separator (', ') after (')')]
> [it/]
> [/for]
> [/template]
>
>
> The exception is :
> org.eclipse.acceleo.engine.AcceleoEvaluationException: Invalid type for
> iteration at line 0 in Module jpaAnnotations for block for (args)
> before('(') separator(', ') after(')').
> org.eclipse.uml2.uml.internal.impl.PropertyImpl was not an instanceof
> String.
>
> Is it a bug ?
> Is there a workaround to make this kind of code working ?
>
> Regards
>
> Sebastien
>
Re: [Acceleo] Use of template result in Sequence of String [message #545415 is a reply to message #545409] Wed, 07 July 2010 17:05 Go to previous messageGo to next message
Sebastien Roy is currently offline Sebastien RoyFriend
Messages: 51
Registered: November 2009
Member
Thank you Edward for your answer.

However, my actual code is a little more complicated than the sample I wrote above.
Actually it would be very tedious to write the actual code of 'aBlock' as a query. Furthermore, there is several different templates that may be implied in the sequence construction.

So my initial question becomes :

Is there a way to transform a template result (i.e a Property) into a String ?

Sebastien
Re: [Acceleo] Use of template result in Sequence of String [message #545517 is a reply to message #545415] Thu, 08 July 2010 07:22 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1638
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------030602090606080200040506
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Sebastien,

You could use the post attribute on template aBlock() to force it in
returning a String (see below), but I don't know if this will help.
We're currently looking into it in order to understand why we end up
with a Sequence of Properties where it should be a Sequence of String.

[template x(a : Type) post(toString())/]

Laurent Goubet
Obeo

Sebastien Roy wrote:
> Thank you Edward for your answer.
>
> However, my actual code is a little more complicated than the sample I
> wrote above.
> Actually it would be very tedious to write the actual code of 'aBlock'
> as a query. Furthermore, there is several different templates that may
> be implied in the sequence construction.
>
> So my initial question becomes :
>
> Is there a way to transform a template result (i.e a Property) into a
> String ?
>
> Sebastien


--------------030602090606080200040506
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------030602090606080200040506--
Re: [Acceleo] Use of template result in Sequence of String [message #545529 is a reply to message #545517] Thu, 08 July 2010 07:54 Go to previous messageGo to next message
Sebastien Roy is currently offline Sebastien RoyFriend
Messages: 51
Registered: November 2009
Member
I just tryed to add the "post(toString())" part to my template.
Unfortunately, it doesn't work.

I've observed that the type returned by the template is not really reproductible. Now I have an 'org.eclipse.emf.ecore.impl.DynamicEObjectImpl' object, with or without the toString() instruction.
Re: [Acceleo] Use of template result in Sequence of String [message #545551 is a reply to message #545350] Thu, 08 July 2010 08:47 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 413
Registered: April 2010
Location: Nantes (France)
Senior Member

We have open a bug in order to track the problem: https://bugs.eclipse.org/bugs/show_bug.cgi?id=319230


Re: [Acceleo] Use of template result in Sequence of String [message #631402 is a reply to message #545551] Thu, 07 October 2010 12:59 Go to previous messageGo to next message
Sebastien Roy is currently offline Sebastien RoyFriend
Messages: 51
Registered: November 2009
Member
Question to the Acceleo team : is there a chance to have this bug corrected in a future version of Acceleo ?
It would make dramaticaly easier to write some parts of my code...

Cheers

Sebastien
Re: [Acceleo] Use of template result in Sequence of String [message #631407 is a reply to message #545350] Thu, 07 October 2010 13:20 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 413
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi,

The next update of Acceleo 3.0 will be SR2 in February and Acceleo 3.1 will be available in June 2011. Right now both Laurent and I are working on another project so we won't be available to correct this problem before the end of the year. I would say that it will be corrected for Acceleo 3.0 SR2 and Acceleo 3.1.0 M4 or M5.

Stephane Begaudeau, Obeo



[Updated on: Thu, 07 October 2010 13:21]

Report message to a moderator

Re: [Acceleo] Use of template result in Sequence of String [message #631500 is a reply to message #545350] Thu, 07 October 2010 18:12 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 413
Registered: April 2010
Location: Nantes (France)
Senior Member

Well Sebastien I have a good news for you.

While taking the bus tonight I thought about this bug once again and I had an idea. Since the first time I tried to solve the problem I didn't find where it was coming from, tonight at home, I tried my idea to see if it was the source of the bug and guess what ? I know where the bug is coming from.

When parsing the module we identify the template call as an (OCL) OperationCallExp and then we convert it to our TemplateInvocation (same thing for queries) but we didn't convert the parameters of the template or the query. Thus if you have a call (template or query) as a parameter like:

[myTemplate(Sequence{myQuery(myValue)})/]

The call of myQuery was still an OperationCallExp and OCL could not resolve that call correctly. So while the diner was in the oven, I went back to this bug and created a fix that you can see here in action:
http://img176.imageshack.us/img176/3369/capturedcran20101007194m.png

The fix may not take into account all form of parameters right now but it will work on a collection of template or query invocations. I'm not sure for example that it would work on this:

[myTemplate(Sequence{Sequence{myQuery(myValue)}})/]

But now I know:
- why it is not working
- where the bug is coming from
- and how to solve the problem

So I will upload this temporary fix on the bugzilla for today and I will get back to this problem a bit later but a patch correcting the problem will be available in Acceleo 3.0.2 (SR2 in February) and in Acceleo 3.1.0 (M3 next month).

Have a great day

Stephane Begaudeau, Obeo



Re: [Acceleo] Use of template result in Sequence of String [message #631620 is a reply to message #631500] Fri, 08 October 2010 08:33 Go to previous message
Sebastien Roy is currently offline Sebastien RoyFriend
Messages: 51
Registered: November 2009
Member
Wow ! I am really impressed by your intution and your implication in Acceleo project.

Was it a bath-featured bus ? Very Happy Archimede had certainly the same when he found his theorem Very Happy

Thank you very much for your analysis and bug fix. It will be very helpfull into my code.

Regards

Sebastien
Previous Topic:[JET] Cross Model Association Lost
Next Topic:[Xpand] EvaluationException, no main found in xpand template
Goto Forum:
  


Current Time: Wed Nov 26 20:48:20 GMT 2014

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

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