|
Re: Implicit collect() flattening and OCLInEcore expression rewrite [message #803714 is a reply to message #803532] |
Tue, 21 February 2012 12:40  |
Eclipse User |
|
|
|
Hi
Must be a bug (https://bugs.eclipse.org/bugs/show_bug.cgi?id=372144)
since I regard the equivalence as the definition.
Regards
Ed Willink
On 21/02/2012 13:11, Filip Krikava wrote:
> I have a question about the implicit collect() and collection flattening:
>
> In slide 48 [1] of the Ed's presentation about OCL it is said that
>
> parents.parents is the same parents->collect(parents)
>
> But there actually seems to be a difference:
>
> Considering a model like this:
>
>
> module _'My.ecore'
> package my : my = 'http://my.me/me'
> {
> class Type {
> property name : String[1];
> property nestedTypes : Type[*] { ordered composes };
> property features : Feature[*] { ordered composes };
> }
> class Feature {
> attribute name : String[1];
> property type : Type[1];
> }
> }
>
>
> I would like to add a derived property allNestedFeatures in Type that would give a set of all its features together with all its features' features, ...
>
> One way to do it is to use:
>
> self.features.type.allNestedFeatures->union(self.features->asSequence())
>
> which should be the same as:
>
> self.features->collect(type)->collect(allNestedFeatures)->union(self.features->asSequence())
>
> but it is not as the second one does not flatten. If I execute it in the Xtext console (replacing the allNestedFeatures with just features) the first one works and the second does not
>
>
> Evaluating:
> features.type.features->union(features->asSequence())
> Results:
> Feature b
> Feature c
>
> Evaluating:
> features->collect(type)->collect(features)->union(features->asSequence())
> Results:
> Parsing failure
> null
> Unresolved operation 'union' for 'Sequence<OrderedSet<My.ecore::my::Feature>>' and 'Sequence<My.ecore::my::Feature>'
>
>
> I could go with the first expression (although still wandering why they are not the same), but the problem is that the OCLInEcore editor does rewrite it to to the second one. In other words to me it seems that there is not a way I can write the first expression in OCLInEcore. Is this a bug?
>
> Thanks,
> Filip
>
> ps: I know I can use closure() to accomplish the same thing more elegantly...
>
> [1]http://www.slideshare.net/EdWillink/enrich-your-models-with-ocl
|
|
|
Powered by
FUDForum. Page generated in 0.04003 seconds