|
|
Re: [QVTo] Return from mapping [message #547798 is a reply to message #547744] |
Mon, 19 July 2010 16:00 |
Ed Willink Messages: 7679 Registered: July 2009 |
Senior Member |
|
|
Hi Sergey
I've raised an OMG issue for the poor example.
I managed to workaround it by doing all the work in init:
mapping Class::jclass2jpackage() : JPackage () {
init {
result := resolveIn(jclass2jpackage,true)
->select(p|self.package=p.name)->first();
if result->isEmpty() then
result := object JPackage {
name := self.package;
}
endif
}
}
There seem to be a fair few areas where QVTo could warn about meta-model
multiplicity impossibilities. I'm not sure how many of these are
actually MDT/OCL's fault.
Ed
On 19/07/2010 15:10, Sergey Boyko wrote:
> Hi Ed,
>
> There's no explicit substitution for the case. However there are some
> possible workarounds:
>
> 1. While it's prohibited by spec to create objects in helpers QVTo
> allows that:
>
> helper Class::jclass2jpackage_helper() : Package {
> var s := resolveIn(Class::jclass2jpackage, Package | true)
> ->select(p|self.package.name=p.name)->first();
> if s <> null then return s endif;
> return self.map jclass2jpackage();
> }
>
> mapping Class::jclass2jpackage() : Package {
> name := self.package.name;
> }
>
>
> 2. Better way is to redesign the mapping so that single return behavior
> is used (for given parameters tuple the out parameters are populated
> using the corresponding trace):
>
> mapping String::jclass2jpackage() : Package {
> name := self;
> }
>
> main() {
> var s := OrderedSet{
> object Class{name := 'a'},
> object Class{name := 'b'},
> object Class{name := 'a'} };
>
> var s1 := s->collect(i|i.name.map jclass2jpackage());
> ...
> }
>
>
> Regards,
> Sergey.
>
>
> Ed Willink wrote:
>> Hi
>>
>> I'm trying to emulate the second example of 8.1.10 in the QVT spec:
>>
>> mapping Class::jclass2jpackage() : JPackage () {
>> init {
>> result := resolveIn(jclass2jpackage,true)
>> ->select(p|self.package=p.name)->first();
>> if result then return;
>> }
>> name := self.package;
>> }
>>
>> which is clearly rather fanciful since
>> - the if expression is not an expression,
>> - the endif is missing
>> - package is a reserved word.
>>
>> When corrected to
>>
>> if result->notEmpty() then return endif;
>>
>> I get a syntax error for a missing return argument although the EBNF
>> shows it to be optional. When changed to
>>
>> if result->notEmpty() then return result endif;
>>
>> I get 'Using "return" from mapping operation is not yet supported'.
>>
>> Is there a recommended way to perform a premature mapping exit?
>>
>> Regards
>>
>> Ed Willink
|
|
|
Powered by
FUDForum. Page generated in 0.03138 seconds