Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Strange behavior for queries using the "iterate" method
[Acceleo] Strange behavior for queries using the "iterate" method [message #1767836] Tue, 11 July 2017 13:27 Go to next message
Mad Vin is currently offline Mad VinFriend
Messages: 35
Registered: September 2013
Member
Hello,

Here is the code of simple queries of a module (no need to comment about the stupidity of the code of these queries, the important thing is to understand the behaviour at compilation and execution) :

[query private getStr(aString : String) : String = aString/]

[query private createStr(contextObj : OclAny, s : String) : String = 'Create ' + s/]

[query public mainQuery(contextObj : OclAny) : String =
OrderedSet{'blabla', 'miammiam'}->iterate(str : String; result : String = 'result=' | result + ' ' + createStr(str)).getStr()/]


At the execution of the "mainQuery" query with the contextObj as a Class, you got the following error :

java.lang.UnsupportedOperationException: Operation createStr(String) is undefined on type org.eclipse.uml2.uml.internal.impl.ClassImpl.


If you remove the call to "getStr()" at the end of the "mainQuery", the execution is OK... But why the behavior of the call to "createStr(str)" inside the "iterate" expression is different with the call to "getStr()" at the end ? I suppose there is something i don't understand with the "iterate" method...

You can see this different behavior at the compilation : if you make a CTRL + mouse click on the call to "createStr(str)" in the "iterate", the editor selects the "createStr" query in the module when it's ok (without the call to "getStr()" at the end), and when it's not ok (with the call to "getStr()" at the end), it opens and selects in the .emtl file view of the module the "createStr(String) : String" method applied on "OclAny_Class" .

Thank you.

Best regards.

Version : Acceleo 3.4.1

[Updated on: Tue, 11 July 2017 13:49]

Report message to a moderator

Re: [Acceleo] Strange behavior for queries using the "iterate" method [message #1767839 is a reply to message #1767836] Tue, 11 July 2017 13:47 Go to previous messageGo to next message
Mad Vin is currently offline Mad VinFriend
Messages: 35
Registered: September 2013
Member
The funny thing is if you replace the call to "getStr()" at the end by a standard method of the String type like "concat('str')" for example : no problem, it works !! =S...

[Updated on: Tue, 11 July 2017 13:53]

Report message to a moderator

Re: [Acceleo] Strange behavior for queries using the "iterate" method [message #1767840 is a reply to message #1767839] Tue, 11 July 2017 13:59 Go to previous messageGo to next message
Mad Vin is currently offline Mad VinFriend
Messages: 35
Registered: September 2013
Member
The easiest way i've found to work around the problem is to store the result of the iterate method in a let statement, then to call the 'getStr()' method on it :

[query public mainQuery(contextObj : OclAny) : String =
let result : String = OrderedSet{'blabla', 'miammiam'}->iterate(str : String; result : String = 'result=' | result + ' ' + createStr(str))
in
result.getStr()
/]
Re: [Acceleo] Strange behavior for queries using the "iterate" method [message #1767845 is a reply to message #1767840] Tue, 11 July 2017 14:27 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5834
Registered: July 2009
Senior Member
Hi

Yes. Simplify it so that Acceleo doesn't get confused.

OCL has a dangerously flexible implicit source capability for use within iterations. MOFM2T defines contextual operations allowing self/first parameter flexibility. The combination of these explains but does not justify your observations. Keep it simple.

Regards

Ed Willink
Re: [Acceleo] Strange behavior for queries using the "iterate" method [message #1767847 is a reply to message #1767845] Tue, 11 July 2017 14:39 Go to previous messageGo to next message
Mad Vin is currently offline Mad VinFriend
Messages: 35
Registered: September 2013
Member
I don't see how Acceleo can be confused, even if you execute the code like this, it doesn't work :

[query public mainQuery(contextObj : OclAny) : String =
(OrderedSet{'blabla', 'miammiam'}->iterate(str : String; result : String = 'result=' | result + ' ' + contextObj.createStr(str))).getStr()/]


Even like this :

[query public mainQuery(contextObj : OclAny) : String =
getStr(OrderedSet{'blabla', 'miammiam'}->iterate(str : String; result : String = 'result=' | result + ' ' + contextObj.createStr(str)))/]


I think there is clearly a problem with the compilator in that way.

[Updated on: Tue, 11 July 2017 14:43]

Report message to a moderator

Re: [Acceleo] Strange behavior for queries using the "iterate" method [message #1767849 is a reply to message #1767847] Tue, 11 July 2017 14:51 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5834
Registered: July 2009
Senior Member
Hi

"confused" is just a polite euphemism for "buggy". I recall raising a Bugzilla for a similar problem.

Regards

Ed Willink
Re: [Acceleo] Strange behavior for queries using the "iterate" method [message #1767850 is a reply to message #1767849] Tue, 11 July 2017 15:05 Go to previous messageGo to next message
Mad Vin is currently offline Mad VinFriend
Messages: 35
Registered: September 2013
Member
Oh ok ^^°... Do you think i can add this bug in bugzilla or you think it is too minor because easily work aroundable ?
Re: [Acceleo] Strange behavior for queries using the "iterate" method [message #1767858 is a reply to message #1767850] Tue, 11 July 2017 16:15 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5834
Registered: July 2009
Senior Member
Hi

Acceleo has comparatively few open bugs and this bug seems like a stupid rather than a really hard problem, so well worth a Bugzilla with repro. I can't see my similar problem.

Regards

Ed Willink
Re: [Acceleo] Strange behavior for queries using the "iterate" method [message #1767864 is a reply to message #1767858] Tue, 11 July 2017 17:08 Go to previous message
Mad Vin is currently offline Mad VinFriend
Messages: 35
Registered: September 2013
Member
Ok... I've created the Bug 519518...

Regards.
Previous Topic:[Acceleo] Use Ecore metamodel in the Acceleo editor without installing a plugin
Next Topic:Acceleo run error
Goto Forum:
  


Current Time: Sat Apr 21 21:36:13 GMT 2018

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

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