Home » Archived » M2M (model-to-model transformation) » [ATL] Insert elements in reference features
[ATL] Insert elements in reference features [message #66400] |
Mon, 19 November 2007 16:17 |
Lorenzo Dalla Vecchia Messages: 58 Registered: July 2009 |
Member |
|
|
Hi again.
I'm having problem inserting elements in reference features of generated
(target model) elements.
Say I have already generated an element with a reference "ref" set to the
elements e1 and e2; what I want to do now is insert element e0 in the value
list of the reference, from Sequence{e1, e2} to Sequence{e0, e1, e2}.
However, when I try the following imperative code:
element.ref <- element.ref->prepend(e0)
I get ref set to {e1, e2, e0}, with e0 *appended* and not prepended.
The same happens if I user insertAt, e0 is still appended.
I even tried to clear the entire sequence of values inside ref to re-add
them in the correct order, and doing so I discovered that the operator <-
used with references *adds* new values, so I could never remove them.
Am I doing something wrong or is this a ATL limitation?
Thanks again.
--
Lorenzo
|
|
|
Re: [ATL] Insert elements in reference features [message #66463 is a reply to message #66400] |
Tue, 20 November 2007 11:20 |
Alfons Laarman Messages: 35 Registered: July 2009 |
Member |
|
|
Hi Lorenzo,
If you can use insertAt, you can also use other OCL function for
Collections on it, for example exclude to remove elements.
Have you tried prepend?
Alfons
Lorenzo Dalla Vecchia a écrit :
> Hi again.
>
> I'm having problem inserting elements in reference features of generated
> (target model) elements.
> Say I have already generated an element with a reference "ref" set to
> the elements e1 and e2; what I want to do now is insert element e0 in
> the value list of the reference, from Sequence{e1, e2} to Sequence{e0,
> e1, e2}.
>
> However, when I try the following imperative code:
>
> element.ref <- element.ref->prepend(e0)
>
> I get ref set to {e1, e2, e0}, with e0 *appended* and not prepended.
> The same happens if I user insertAt, e0 is still appended.
>
> I even tried to clear the entire sequence of values inside ref to re-add
> them in the correct order, and doing so I discovered that the operator
> <- used with references *adds* new values, so I could never remove them.
>
> Am I doing something wrong or is this a ATL limitation?
> Thanks again.
>
> --
> Lorenzo
>
|
|
|
Re: [ATL] Insert elements in reference features [message #66527 is a reply to message #66463] |
Tue, 20 November 2007 16:34 |
Lorenzo Dalla Vecchia Messages: 58 Registered: July 2009 |
Member |
|
|
Alfons,
yes I tried with all relevant OCL operations: excludes, prepend, insertAt
etc.
My guess is that the problem is not with the generation of the expression on
the right hand side of the assignment, but with the assignment itself.
In the following, with ref={e1,e2}:
element.ref <- element.ref->prepend(e0)
the expression on the right side, element.ref->prepend(e0) is correctly
computed as {e0,e1,e2} but when assigned the new element, e0, looses its
place at the start of the sequence.
I suspect that the assignment operation is done by checking which of the new
elements on the right is missing on the reference, and by appending the
"new" elements to the feature sequence. I event tried:
element.ref <- Sequence{}
and it leaves the ref list untouched.
So, <- is like an "add to" more than "assign to": is there a way to even
clear a reference list?
Thanks.
--
Lorenzo
> If you can use insertAt, you can also use other OCL function for
> Collections on it, for example exclude to remove elements.
> Have you tried prepend?
>
> Lorenzo Dalla Vecchia a écrit :
>> Hi again.
>>
>> I'm having problem inserting elements in reference features of generated
>> (target model) elements.
>> Say I have already generated an element with a reference "ref" set to the
>> elements e1 and e2; what I want to do now is insert element e0 in the
>> value list of the reference, from Sequence{e1, e2} to Sequence{e0, e1,
>> e2}.
>>
>> However, when I try the following imperative code:
>>
>> element.ref <- element.ref->prepend(e0)
>>
>> I get ref set to {e1, e2, e0}, with e0 *appended* and not prepended.
>> The same happens if I user insertAt, e0 is still appended.
>>
>> I even tried to clear the entire sequence of values inside ref to re-add
>> them in the correct order, and doing so I discovered that the operator <-
>> used with references *adds* new values, so I could never remove them.
>>
>> Am I doing something wrong or is this a ATL limitation?
>> Thanks again.
>>
>> --
>> Lorenzo
>>
>
|
|
|
Re: [ATL] Insert elements in reference features [message #66827 is a reply to message #66527] |
Tue, 27 November 2007 03:16 |
Frédéric Jouault Messages: 572 Registered: July 2009 |
Senior Member |
|
|
Lorenzo,
You are right, <- only adds new elements. The rationale behind this is
that you do not care about control flow in declarative code. Therefore,
there is no notion of order.
However, imperative <- (i.e., class BindingStat in ATL metamodel) should
probably have a different behavior.
Please, ask for this feature on the bugzilla.
Regards,
Frédéric Jouault
Lorenzo Dalla Vecchia wrote:
> Alfons,
>
> yes I tried with all relevant OCL operations: excludes, prepend,
> insertAt etc.
> My guess is that the problem is not with the generation of the
> expression on the right hand side of the assignment, but with the
> assignment itself.
> In the following, with ref={e1,e2}:
>
> element.ref <- element.ref->prepend(e0)
>
> the expression on the right side, element.ref->prepend(e0) is correctly
> computed as {e0,e1,e2} but when assigned the new element, e0, looses its
> place at the start of the sequence.
> I suspect that the assignment operation is done by checking which of the
> new elements on the right is missing on the reference, and by appending
> the "new" elements to the feature sequence. I event tried:
>
> element.ref <- Sequence{}
>
> and it leaves the ref list untouched.
> So, <- is like an "add to" more than "assign to": is there a way to even
> clear a reference list?
> Thanks.
>
> --
> Lorenzo
>
>> If you can use insertAt, you can also use other OCL function for
>> Collections on it, for example exclude to remove elements.
>> Have you tried prepend?
>>
>> Lorenzo Dalla Vecchia a écrit :
>>> Hi again.
>>>
>>> I'm having problem inserting elements in reference features of
>>> generated (target model) elements.
>>> Say I have already generated an element with a reference "ref" set to
>>> the elements e1 and e2; what I want to do now is insert element e0 in
>>> the value list of the reference, from Sequence{e1, e2} to
>>> Sequence{e0, e1, e2}.
>>>
>>> However, when I try the following imperative code:
>>>
>>> element.ref <- element.ref->prepend(e0)
>>>
>>> I get ref set to {e1, e2, e0}, with e0 *appended* and not prepended.
>>> The same happens if I user insertAt, e0 is still appended.
>>>
>>> I even tried to clear the entire sequence of values inside ref to
>>> re-add them in the correct order, and doing so I discovered that the
>>> operator <- used with references *adds* new values, so I could never
>>> remove them.
>>>
>>> Am I doing something wrong or is this a ATL limitation?
>>> Thanks again.
>>>
>>> --
>>> Lorenzo
>>>
>>
>
|
|
| |
Goto Forum:
Current Time: Fri Dec 27 02:52:18 GMT 2024
Powered by FUDForum. Page generated in 0.03240 seconds
|