Strange result in query [message #667299] |
Wed, 27 April 2011 17:54  |
Eclipse User |
|
|
|
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 #667809 is a reply to message #667806] |
Mon, 02 May 2011 06:07   |
Eclipse User |
|
|
|
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
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04271 seconds