[QVTo] confused [message #696974] |
Fri, 15 July 2011 08:39 |
Wilbert Alberts Messages: 209 Registered: June 2010 |
Senior Member |
|
|
Hi,
I created a metamodel consisting of a class called Population which contains a number of Users, Items and Matches.
The model is expected to hold Users and Items at first. Matches should be generated by the following transformation.
modeltype RZH uses Ruilen('http://ruilenzonderhuilen.com');
transformation GenerateMatches(inout mdl: RZH);
main() {
log('size:', mdl->objectsOfType(Population)->size());
log('size:', mdl->objects()[Population]->size());
log('size:', mdl.objectsOfType(Population)->size());
log('size:', mdl.objects()[Population]->size());
log('mdl', mdl);
mdl.objectsOfType(RZH::Population).map genMatches();
}
helper createMatch(in usr1: User, in usr2: User) : Match
{
log('Creating Match of ' + usr1.id + ' and' + usr2.id);
return object Match {
u1 := usr1;
u2 := usr2;
}
}
mapping inout Population::genMatches() : Population {
init {
self.matches := Set{};
}
population {
log('Generating matches');
self.matches := self.users -> collect(u1 | self.users->collect(u2 | createMatch(u1, u2)))
}
}
I'm having troubles understanding the behavior of the objects[], objectsOfType with and without combinations of '.' and '->'.
The model I use for testing consists of one (root) instance of Population (with a number of Users). When I run the transformation, it prints:
size:, data: 1
size:, data: 0
size:, data: 0
size:, data: 0
mdl, data: RZH - http://ruilenzonderhuilen.com
Somehow, the genMatches mapping isn't invoked at all. What am I doing wrong?
Greetings,
Wilbert.
|
|
|
Re: [QVTo] confused [message #697031 is a reply to message #696974] |
Fri, 15 July 2011 10:47 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi Wilbert
"Somehow, the genMatches mapping isn't invoked at all. What am I doing
wrong? "
You're not using the one you found worked.
One day the specification may make the following more explicit:
object . feature => object navigation
collection -> feature => collection navigation
collection . feature => collection -> collect( feature )
object -> feature => object . oclAsSet() -> feature
OclAny::oclAsSet() => Set{ self }
OclVoid::oclAsSet() => Set{}
OclInvalid::oclAsSet() => invalid
Regards
Ed Willink
On 15/07/2011 09:39, Wilbert Alberts wrote:
> Hi,
>
> I created a metamodel consisting of a class called Population which
> contains a number of Users, Items and Matches.
>
> The model is expected to hold Users and Items at first. Matches should
> be generated by the following transformation.
>
> modeltype RZH uses Ruilen('http://ruilenzonderhuilen.com');
>
> transformation GenerateMatches(inout mdl: RZH);
>
> main() {
> log('size:', mdl->objectsOfType(Population)->size());
> log('size:', mdl->objects()[Population]->size());
> log('size:', mdl.objectsOfType(Population)->size());
> log('size:', mdl.objects()[Population]->size());
> log('mdl', mdl);
> mdl.objectsOfType(RZH::Population).map genMatches();
> }
>
> helper createMatch(in usr1: User, in usr2: User) : Match
> {
> log('Creating Match of ' + usr1.id + ' and' + usr2.id);
> return object Match {
> u1 := usr1;
> u2 := usr2;
> }
> }
>
> mapping inout Population::genMatches() : Population {
> init {
> self.matches := Set{};
> }
> population {
> log('Generating matches');
> self.matches := self.users -> collect(u1 |
> self.users->collect(u2 | createMatch(u1, u2)))
> }
> }
>
> I'm having troubles understanding the behavior of the objects[],
> objectsOfType with and without combinations of '.' and '->'.
>
> The model I use for testing consists of one (root) instance of
> Population (with a number of Users). When I run the transformation, it
> prints:
>
> size:, data: 1
> size:, data: 0
> size:, data: 0
> size:, data: 0
> mdl, data: RZH - http://ruilenzonderhuilen.com
>
> Somehow, the genMatches mapping isn't invoked at all. What am I doing
> wrong?
>
> Greetings,
> Wilbert.
>
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.02851 seconds