Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Implicit collect() flattening and OCLInEcore expression rewrite
Implicit collect() flattening and OCLInEcore expression rewrite [message #803532] Tue, 21 February 2012 13:10 Go to next message
Filip Krikava is currently offline Filip KrikavaFriend
Messages: 45
Registered: January 2012
Member
Hi,

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
  • Attachment: ocltest2.zip
    (Size: 3.53KB, Downloaded 169 times)
Re: Implicit collect() flattening and OCLInEcore expression rewrite [message #803714 is a reply to message #803532] Tue, 21 February 2012 17:40 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
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
Previous Topic:CompleteOCL and Invocation and Setting Delegates
Next Topic:Compile Ecore
Goto Forum:
  


Current Time: Thu Apr 25 07:47:08 GMT 2024

Powered by FUDForum. Page generated in 0.03217 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top