[QVTO] How to call different mappings based on some predicate? [message #490594] |
Fri, 09 October 2009 10:15  |
Eclipse User |
|
|
|
Hi,
in my target metamodel there's an abstract class Person, and two
concrete subclasses Male and Female. The class Genealogy references a
set of Persons. So I have:
--8<---------------cut here---------------start------------->8---
main() {
src.objectsOfType(FamilyTree) -> map familyTree2Genealogy();
}
mapping FamilyTree::familyTree2Genealogy() : Genealogy {
persons := self.members -> map member2Person();
}
--8<---------------cut here---------------end--------------->8---
Additionally, for the concrete Male/Female I have those mappings:
--8<---------------cut here---------------start------------->8---
mapping Member::member2Female() : Female
when {self.isFemale()}
{
fullName := self.firstName + ' ' + self.familyName();
}
mapping Member::member2Male() : Male
when {not self.isFemale()}
{
fullName := self.firstName + ' ' + self.familyName();
}
--8<---------------cut here---------------end--------------->8---
But I cannot figure out how to define the member2Person() mapping so
that it dispatches to the right mapping. Reading the QVT spec, it looks
to me that the disjuncts keyword is the thing I'm looking for. But
--8<---------------cut here---------------start------------->8---
mapping Member::member2Person() : Person
disjuncts member2Female, member2Male() {}
--8<---------------cut here---------------end--------------->8---
shows errors becauso of "Unresolved mapping operation references" for
member2Female and member2Male.
What am I doing wrong?
And another minor question: In the QVT spec there seem to be a lot of
syntactical constructs that won't work. For example, there often things
like
if (<predicate>) return 'Foo';
are used, but it seems that in reality I need to write
if (<predicate>) then return 'Foo' else return null elseif;
so I cannot omit the then and else. Why is that difference?
Bye,
Tassilo
|
|
|
Re: [QVTO] How to call different mappings based on some predicate? [message #490844 is a reply to message #490594] |
Sun, 11 October 2009 19:30   |
Eclipse User |
|
|
|
Originally posted by: dvorak.radek.gmail.com
Hi Tassilo,
See inlined comments.
Regards,
/Radek
>
> But I cannot figure out how to define the member2Person() mapping so
> that it dispatches to the right mapping. Reading the QVT spec, it looks
> to me that the disjuncts keyword is the thing I'm looking for. But
>
> --8<---------------cut here---------------start------------->8---
> mapping Member::member2Person() : Person
> disjuncts member2Female, member2Male() {}
> --8<---------------cut here---------------end--------------->8---
>
> shows errors becauso of "Unresolved mapping operation references" for
> member2Female and member2Male.
>
> What am I doing wrong?
Use qualified reference to mapping operations, like
disjuncts Member::member2Male, Member::member2Female {}
>
> And another minor question: In the QVT spec there seem to be a lot of
> syntactical constructs that won't work. For example, there often things
> like
>
> if (<predicate>) return 'Foo';
>
> are used, but it seems that in reality I need to write
>
> if (<predicate>) then return 'Foo' else return null elseif;
>
> so I cannot omit the then and else. Why is that difference?
You can do the following:
if (<predicate>) then
return 'Foo'
endif;
>
> Bye,
> Tassilo
|
|
|
Re: [QVTO] How to call different mappings based on some predicate? [message #490907 is a reply to message #490844] |
Mon, 12 October 2009 10:55  |
Eclipse User |
|
|
|
"radek dvorak" <dvorak.radek@gmail.com> writes:
Hi Radek,
>> But I cannot figure out how to define the member2Person() mapping so
>> that it dispatches to the right mapping. Reading the QVT spec, it looks
>> to me that the disjuncts keyword is the thing I'm looking for. But
>>
>> --8<---------------cut here---------------start------------->8---
>> mapping Member::member2Person() : Person
>> disjuncts member2Female, member2Male() {}
>> --8<---------------cut here---------------end--------------->8---
>>
>> shows errors becauso of "Unresolved mapping operation references" for
>> member2Female and member2Male.
>>
>> What am I doing wrong?
>
> Use qualified reference to mapping operations, like
> disjuncts Member::member2Male, Member::member2Female {}
Ah, this does the trick. Thanks a lot!
> You can do the following:
>
> if (<predicate>) then
> return 'Foo'
> endif;
Great, that also works. The problem was that I always omitted the
semicolon.
Bye,
Tassilo
|
|
|
Powered by
FUDForum. Page generated in 0.03667 seconds