self->asSet()->closure(eContents()->select(oclIsKindOf(model::YYY) or oclIsKindOf(model::ZZZ)).oclAsType(EObject))->select(a:EObject| a.oclIsKindOf(model::xxx) and a.oclAsType(model::xxx).name='XX')->collect(a:EObject| a.eContainer())->asSet()
It gets the container element, of the element with kind 'xxx' having the name 'XX'.
I want to use the operation indexOf to get the position of the element 'XX' inside the sequence of elements in the container element.
Your 'solution' seems incredibly complex and suspect.
Given that you can do such things with closure, why does indexOf cause
you difficulties?
Regards
Ed Willink
On 03/08/2013 18:14, Archevo tarek wrote:
> Hi,
>
> I'm using this following request:
>
> self->asSet()->closure(eContents()->select(oclIsKindOf(model::YYY) or
> oclIsKindOf(model::ZZZ)).oclAsType(EObject))->select(a:EObject|
> a.oclIsKindOf(model::xxx) and
> a.oclAsType(model::xxx).name='XX')->collect(a:EObject|
> a.eContainer())->asSet()
>
> It gets the container element, of the element with kind 'xxx' having
> the name 'XX'.
>
> I want to use the operation indexOf to get the position of the element
> 'XX' inside the sequence of elements in the container element.
>
> Thanks.
Hi ed,
Thanks for your answer.
I told you i'm novice in OCL, and i'm learning by examples. I found this solution with closure after long tests thanks to your assistance. I know that indexOf needs an object as an argument. The elements in the collection given by 'collect' are EObject elements. The collect operation gets the container element inside which other elements may exist. I just want to get the index (position) of the element with kind 'xxx' having the name 'XX' inside the collection. That's what i need.
I'm steel testing and trying some requests using the indexOf() operation, for example this one in the Xtext Console:
self->asSet()->closure(oclContents()->select(oclIsKindOf(model::Activity) or oclIsKindOf(model::ExtensibleElement)))
->select(a:model::Activity| a.oclIsKindOf(model::Assign) and a.oclAsType(model::Assign).name='Assign2')
->collect(a:model::Assign| a.oclContainer())->asOrderedSet()->indexOf(model::Assign)
Results:
Missing value for 'indexOf'
self->closure(oclContents())
->select(oclIsKindOf(model::Activity) or
oclIsKindOf(model::ExtensibleElement))
->select(oclIsKindOf(model::Assign) and
oclAsType(model::Assign).name='Assign2')
->collect(oclContainer())
->asOrderedSet()
->indexOf(model::Assign)
we can see two funnies.
a) the source of the indexOf is an asOrderedSet() suggesting that the
ordeting will be indeterminate, and so the index of limited utility.
b) the argument is a type so it is unlikely that you will have any
content whose identity is equal to their type
The navigation makes very little sense to me, and so I suggest that you
have failed to understand what problem you want to solve, or the
metamodel that you are using is really not fit for purpose.
Regards
Ed Willink
On 03/08/2013 19:32, Archevo tarek wrote:
> Hi ed,
> Thanks for your answer.
> I told you i'm novice in OCL, and i'm learning by examples. I found
> this solution with closure after long tests thanks to your assistance.
> I know that indexOf needs an object as an argument. The elements in
> the collection given by 'collect' are EObject elements. The collect
> operation gets the container element inside which other elements may
> exist. I just want to get the index (position) of the element with
> kind 'xxx' having the name 'XX' inside the collection. That's what i
> need.
> I'm steel testing and trying some requests using the indexOf()
> operation, for example this one in the Xtext Console:
>
>
> self->asSet()->closure(oclContents()->select(oclIsKindOf(model::Activity)
> or oclIsKindOf(model::ExtensibleElement)))
> ->select(a:model::Activity| a.oclIsKindOf(model::Assign) and
> a.oclAsType(model::Assign).name='Assign2')
> ->collect(a:model::Assign|
> a.oclContainer())->asOrderedSet()->indexOf(model::Assign)
>
> Results:
> Missing value for 'indexOf'
>
>
> Any help.
> Thanks in advance.
>
a) The asOrderedSet() is just for the indexOf() operation which work on a OrderedSet or a Sequence.
In the obtained container element, elements are for sure having a determined sequencing since it is selected from an instance of the metamodel which i have not modified yet, then, the index here is very important for my needs.
b) you are absolutely wright for type.
The expression i sended in my previuos post works fine (thanks to your assistance) and it gives the good result. May be it is a bit complex and this is due i think to the metamodel i'm working on it (i posted in my previous posts) which is very complex.
Your computation is a closure over a set. There is no determinism to the
ordering.
Regards
Ed Willink
On 05/08/2013 19:24, Archevo tarek wrote:
> Hi ed,
> Thanks for answering me.
>
> a) The asOrderedSet() is just for the indexOf() operation which work
> on a OrderedSet or a Sequence. In the obtained container element,
> elements are for sure having a determined sequencing since it is
> selected from an instance of the metamodel which i have not modified
> yet, then, the index here is very important for my needs.
>
> b) you are absolutely wright for type.
>
> The expression i sended in my previuos post works fine (thanks to your
> assistance) and it gives the good result. May be it is a bit complex
> and this is due i think to the metamodel i'm working on it (i posted
> in my previous posts) which is very complex.
>
>
>
>