Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVTo] Return from mapping
[QVTo] Return from mapping [message #547523] Sun, 18 July 2010 07:54 Go to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
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
Re: [QVTo] Return from mapping [message #547744 is a reply to message #547523] Mon, 19 July 2010 14:10 Go to previous messageGo to next message
Sergey Boyko is currently offline Sergey BoykoFriend
Messages: 171
Registered: July 2009
Senior Member
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
Re: [QVTo] Return from mapping [message #547798 is a reply to message #547744] Mon, 19 July 2010 16:00 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
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
Previous Topic:[ATL] Can I apply helpers just on classes used as main class?
Next Topic:programmatically invoke ATL
Goto Forum:
  


Current Time: Fri Apr 26 06:14:32 GMT 2024

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

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

Back to the top