Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Strange result in query
Strange result in query [message #667299] Wed, 27 April 2011 17:54 Go to next message
Hallvard Traetteberg is currently offline Hallvard Traetteberg
Messages: 594
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Hi,

I have tried the following recursive query (it traverses up a chain of
Package objects, to compute the full name):

[query public packageFullName(pack : Package, suffix : String) : String =
if pack.oclIsUndefined() then suffix else
packageFullName(pack._package, pack.name + '.' + suffix) endif
/]

If called on a chain of packages with names org.eclipse.tests it returns
<undefined-object>.org.eclipse where <undefined-object> is the result of
calling oclUndefined.toString(). It is as if the pack.name expression in
pack.name + '.' + suffix is interpreted as pack._package.name.

However, the following works:

[query public packageFullName(pack : Package, suffix : String) : String =
if pack.oclIsUndefined() then suffix else let suffix : String =
pack.name + '.' + suffix in packageFullName(pack._package, suffix) endif
/]

I.e. the argument is computed before the recursive call to
packageFullName. I cannot understand why the result should differ and be
wrong in the first case.

Hallvard
Re: Strange result in query [message #667790 is a reply to message #667299] Mon, 02 May 2011 05:02 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1625
Registered: July 2009
Senior Member
Hi Hallvard,

Seems to me like a variable leak in Acceleo. Could you raise a bug against M2T/Acceleo for this?

As for what you are trying to achieve ... Wouldn't it be easier with something like :

[ancestors(Package)->reverse().name->sep('.')/]

i.e "retrieve all ancestors of type "Package", reverse the list so that the root is first in the list, get all their names, then separate these names with dots". This is what we usually use when computing qualified names.

Laurent Goubet
Obeo
Re: Strange result in query [message #667805 is a reply to message #667790] Mon, 02 May 2011 05:44 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard Traetteberg
Messages: 594
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 02.05.11 11.02, Laurent Goubet wrote:
>
> Seems to me like a variable leak in Acceleo. Could you raise a
> https://bugs.eclipse.org/bugs/enter_bug.cgi?product=M2T& component=Acceleo for
> this?

Done: https://bugs.eclipse.org/bugs/show_bug.cgi?id=344424

> As for what you are trying to achieve ... Wouldn't it be easier with
> something like :
>
> [ancestors(Package)->reverse().name->sep('.')/]

I didn't know about the ancestors function, thanks! However, the root
package is not the root of the model, so I think this would give me an
extra element that I need to remove (before or after doing reverse, I
guess).

Ideally, there is I would like to use a function that traverses along a
named relation (not necessarily the ancestor chain), 'package' in my
case, and collects them until it is null/empty. Does such a function
exist? Can I perhaps use OCL iterate construct?

Hallvard
Re: Strange result in query [message #667806 is a reply to message #667805] Mon, 02 May 2011 05:48 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard Traetteberg
Messages: 594
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 02.05.11 11.44, Hallvard Trætteberg wrote:
> On 02.05.11 11.02, Laurent Goubet wrote:
>>
>> Seems to me like a variable leak in Acceleo. Could you raise a
>> https://bugs.eclipse.org/bugs/enter_bug.cgi?product=M2T& component=Acceleo
>> for
>> this?
>
> Done: https://bugs.eclipse.org/bugs/show_bug.cgi?id=344424
>
>> As for what you are trying to achieve ... Wouldn't it be easier with
>> something like :
>>
>> [ancestors(Package)->reverse().name->sep('.')/]
>
> I didn't know about the ancestors function, thanks! However, the root
> package is not the root of the model, so I think this would give me an
> extra element that I need to remove (before or after doing reverse, I
> guess).

Sorry, I didn't notice the Package (oclType) argument, which filters out
non-Package object. Thanks for the tip!

Hallvard
Re: Strange result in query [message #667809 is a reply to message #667806] Mon, 02 May 2011 06:07 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard Traetteberg
Messages: 594
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 02.05.11 11.48, Hallvard Trætteberg wrote:
> On 02.05.11 11.44, Hallvard Trætteberg wrote:
>> On 02.05.11 11.02, Laurent Goubet wrote:
>>>
>>> Seems to me like a variable leak in Acceleo. Could you raise a
>>> https://bugs.eclipse.org/bugs/enter_bug.cgi?product=M2T& component=Acceleo
>>>
>>> for
>>> this?
>>
>> Done: https://bugs.eclipse.org/bugs/show_bug.cgi?id=344424
>>
>>> As for what you are trying to achieve ... Wouldn't it be easier with
>>> something like :
>>>
>>> [ancestors(Package)->reverse().name->sep('.')/]
>>
>> I didn't know about the ancestors function, thanks! However, the root
>> package is not the root of the model, so I think this would give me an
>> extra element that I need to remove (before or after doing reverse, I
>> guess).
>
> Sorry, I didn't notice the Package (oclType) argument, which filters out
> non-Package object. Thanks for the tip!

Update: ancestors(Package)->reverse().name gives an error marker. I
think it's because reverse isn't recognized, since
ancestors(Package).name works. BTW, I'm using Acceleo 3.0.2 with Helios.

Hallvard
Re: Strange result in query [message #667818 is a reply to message #667299] Mon, 02 May 2011 06:32 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1625
Registered: July 2009
Senior Member
Hallvard,

I know we've fixed a number of bugs with both the "reverse" and "ancestors" services ... but I don't remember which Embarrassed . The 3.1.0 M7 build for Acceleo will be available tomorrow, and it should fix the issue you have with this query.

In the meantime, and if memory serves, you should be able to use this query instead :

[ancestors(Package)->asSequence()->reverse().name->sep('.')/]

As I seem to remember something about "ancestors" not being statically typed to a Sequence or OrderedSet (i.e. an ordered collection) and thus "reverse" not being applicable.

If that doesn't fix it, could you provide me with the message associated with this compilation error?

Laurent Goubet
Obeo
Re: Strange result in query [message #667836 is a reply to message #667818] Mon, 02 May 2011 08:09 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard Traetteberg
Messages: 594
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 02.05.11 12.32, Laurent Goubet wrote:
>
> [ancestors(Package)->asSequence()->reverse().name->sep('.')/]

This does not work, either.

> If that doesn't fix it, could you provide me with the message associated
> with this compilation error?

The error marker's message is "Unrecognized variable: (name)". As I
said, ancestors(Package).name->sep('.') works fine, so I think the
problem is that reverse() is missing.

Hallvard
Re: Strange result in query [message #667884 is a reply to message #667299] Mon, 02 May 2011 11:12 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1625
Registered: July 2009
Senior Member
ha, that one Razz. It has been fixed too. The problem was that "reverse" lost the typing of the collection, ancestors(Package) returns a Collection(Package) but "Collection(Package)->reverse()" returns a Collection(T) ... and "name" does not exist on "T".

You can work around this by manually re-casting :

[ancestors(Package)->reverse().oclAsType(Package).name->sep('.')/]

These problems are fixed in Acceleo 3.1.

Laurent Goubet
Obeo
Re: Strange result in query [message #667935 is a reply to message #667884] Mon, 02 May 2011 16:07 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard Traetteberg
Messages: 594
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 02.05.11 17.12, Laurent Goubet wrote:
> ha, that one :p. It has been fixed too. The problem was that "reverse"
> lost the typing of the collection, ancestors(Package) returns a
> Collection(Package) but "Collection(Package)->reverse()" returns a
> Collection(T) ... and "name" does not exist on "T".

I understand. I can imagine it is a bit tricky to get everything correct.

> You can work around this by manually re-casting :
> [ancestors(Package)->reverse().oclAsType(Package).name->sep('.')/]

When you use -> it is a method on the collection (object), right. While
when you use . it applies to every element in the collection? So
..oclAsType(Package) means the same as ->oclAsType(Sequence(Package))
(not sure if that's correct ocl, but you understand what I mean)?

> These problems are fixed in Acceleo 3.1.

Which is coming to a place near you, soon :-)

Hallvard
Re: Strange result in query [message #667971 is a reply to message #667935] Tue, 03 May 2011 03:39 Go to previous message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1625
Registered: July 2009
Senior Member
Quote:

When you use -> it is a method on the collection (object), right. While
when you use . it applies to every element in the collection? So
..oclAsType(Package) means the same as ->oclAsType(Sequence(Package))
(not sure if that's correct ocl, but you understand what I mean)?



Yup, though "oclAsType" cannot be used on a Collection (with a "->") AFAIK.

Quote:

Quote:

These problems are fixed in Acceleo 3.1.



Which is coming to a place near you, soon Smile



The M7 will be available today on the Milestones update site.

Laurent Goubet
Obeo
Previous Topic:[Acceleo] use of macro / let(loop)
Next Topic:[ACCELEO] problem to run generator
Goto Forum:
  


Current Time: Fri Aug 22 04:14:42 EDT 2014

Powered by FUDForum. Page generated in 0.02005 seconds