Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVTO] How to cast and do a return?
[QVTO] How to cast and do a return? [message #484801] Wed, 09 September 2009 11:51 Go to next message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

How can I cast objects after oclIsTypeOf to that type and how can I do a
"return;" as in Java?

best regards,
Gilbert
Re: [QVTO] How to cast and do a return? [message #484815 is a reply to message #484801] Wed, 09 September 2009 12:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dvorak.radek.gmail.com

Hi Gilbert,

You cast by using oclAsType(Foo) operation from the OCL Standard Library.

You may return from helper operations exactly the same way as in Java:

helper String::toUpperCase() : String {
return self.toUpper();
}


Regards,
/Radek


On Wed, 09 Sep 2009 13:51:21 +0200, Gilbert Mirenque <formatzeh@gmx.de>
wrote:

> How can I cast objects after oclIsTypeOf to that type and how can I do a
> "return;" as in Java?
>
> best regards,
> Gilbert
Re: [QVTO] How to cast and do a return? [message #484889 is a reply to message #484815] Wed, 09 September 2009 15:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

Thanks Radek, the casting thing works. But the return thing doesn't. In
the following mapping

mapping CMM::ConceptualModel::addCommunicationModel(inout rootModel :
CMM::CompositionModel)
{
if(self.container() = rootModel)
then{
if(rootModel.oclIsTypeOf(CompositeComponent))
then{
if(rootModel.oclAsType(CompositeComponent).referencedComposi tionModel
= null)
then{
// here I want to just return or at least leave the outer if
return;
}endif;
}endif;
// some computations
} else {
log('container != rootModel (' + self.container().metaClassName() +
',' + rootModel.metaClassName() + ')', self) when true;
}endif;
}

I just want to return or at least leave the outer if after the casting.
How do I achieve this? The editor gives me the following error:

Using ''return'' from mapping operation is not yet supported

best regards,
Gilbert
Re: [QVTO] How to cast and do a return? [message #484940 is a reply to message #484889] Wed, 09 September 2009 19:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dvorak.radek.gmail.com

Hi Gilbert,

Using 'return' from mapping operations is limitation of the current QVTO
release.
The reason is that a mapping typically has a return type and consequently
a predefined 'result' variable, which receives its final value within or
just
in the end of 'init' section.
It might be a bit confusing if a mapping returned (via explicit return
expression)
a value different from the one already recorded in traces.

The OMG spec is not clear about this situation so we imposed this
limitation,
thinking it can always be solved in an alternative way.

In your mapping we actually could allow explicit return as there is no
result
variable involved.

However, for now, I assume you can just restructure your mapping to avoid
the need for
return expression.

We also have to rethink some other cases to make things more flexible.

Regards,
/Radek



On Wed, 09 Sep 2009 17:48:31 +0200, Gilbert Mirenque <formatzeh@gmx.de>
wrote:

> Thanks Radek, the casting thing works. But the return thing doesn't. In
> the following mapping
>
> mapping CMM::ConceptualModel::addCommunicationModel(inout rootModel :
> CMM::CompositionModel)
> {
> if(self.container() = rootModel)
> then{
> if(rootModel.oclIsTypeOf(CompositeComponent))
> then{
> if(rootModel.oclAsType(CompositeComponent).referencedComposi tionModel
> = null)
> then{
> // here I want to just return or at least leave the outer if
> return;
> }endif;
> }endif;
> // some computations
> } else {
> log('container != rootModel (' + self.container().metaClassName() +
> ',' + rootModel.metaClassName() + ')', self) when true;
> }endif;
> }
>
> I just want to return or at least leave the outer if after the casting.
> How do I achieve this? The editor gives me the following error:
>
> Using ''return'' from mapping operation is not yet supported
>
> best regards,
> Gilbert
Re: [QVTO] How to cast and do a return? [message #484993 is a reply to message #484940] Thu, 10 September 2009 07:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

Hi Radek,
Ok thank you. Yes I can restructure the mapping. But you mentioned that
mappings normally should return something. Maybe it would be better in
my case that I refactor my mapping into a helper? I fear that I can read
about the exact intention of mapping and helper in the QVT spec from the
OMG :(

best regards,
Gilbert

radek dvorak wrote:
> Hi Gilbert,
>
> Using 'return' from mapping operations is limitation of the current QVTO
> release.
> The reason is that a mapping typically has a return type and consequently
> a predefined 'result' variable, which receives its final value within or
> just
> in the end of 'init' section.
> It might be a bit confusing if a mapping returned (via explicit return
> expression)
> a value different from the one already recorded in traces.
>
> The OMG spec is not clear about this situation so we imposed this
> limitation,
> thinking it can always be solved in an alternative way.
>
> In your mapping we actually could allow explicit return as there is no
> result
> variable involved.
>
> However, for now, I assume you can just restructure your mapping to
> avoid the need for
> return expression.
>
> We also have to rethink some other cases to make things more flexible.
>
> Regards,
> /Radek
>
>
>
Re: [QVTO] How to cast and do a return? [message #485035 is a reply to message #484993] Thu, 10 September 2009 09:59 Go to previous message
Eclipse UserFriend
Originally posted by: dvorak.radek.gmail.com

Hi Gilbert,

You do not have to return a result value explicitly from mappings.
The result object will be created for you implicitly, unless
you assign it explicitly via the predefined 'result' variable,
which actually always represents your return value.

If a mapping that defines a return type does not use explicit
return statement, it still implicitly returns the value of the 'result'
variable to the caller.

As I have mentioned, in your case there is no return type declared,
which is internally mapped to OclVoid type and must always result
in 'null' value. Basically, it would be used purely for controlling
the execution flow.

If you need to create, modify your models use mapping operation.
It gives you some benefits like implicit instantiation, traceability,
mapping reuse mechanism.

As for refactoring, hard to guess what you intend to do. Just try out
and come here with a particular problem to solve.

Perhaps, you might want to look for this semantics at
http://www.eclipse.org/m2m/qvto/doc/M2M-QVTO.pdf,
I believe it should be easier to understand then the OMG spec.

Regards,
/Radek


On Thu, 10 Sep 2009 09:36:42 +0200, Gilbert Mirenque <formatzeh@gmx.de>
wrote:

> Hi Radek,
> Ok thank you. Yes I can restructure the mapping. But you mentioned that
> mappings normally should return something. Maybe it would be better in
> my case that I refactor my mapping into a helper? I fear that I can read
> about the exact intention of mapping and helper in the QVT spec from the
> OMG :(
>
> best regards,
> Gilbert
>
> radek dvorak wrote:
>> Hi Gilbert,
>>
>> Using 'return' from mapping operations is limitation of the current QVTO
>> release.
>> The reason is that a mapping typically has a return type and
>> consequently
>> a predefined 'result' variable, which receives its final value within or
>> just
>> in the end of 'init' section.
>> It might be a bit confusing if a mapping returned (via explicit return
>> expression)
>> a value different from the one already recorded in traces.
>>
>> The OMG spec is not clear about this situation so we imposed this
>> limitation,
>> thinking it can always be solved in an alternative way.
>>
>> In your mapping we actually could allow explicit return as there is no
>> result
>> variable involved.
>>
>> However, for now, I assume you can just restructure your mapping to
>> avoid the need for
>> return expression.
>>
>> We also have to rethink some other cases to make things more flexible.
>>
>> Regards,
>> /Radek
>>
>>
>>
Previous Topic:call of lazy rule
Next Topic:[ATL] Problem refining mode and lazy rules/Iterative target pattern elem
Goto Forum:
  


Current Time: Thu Apr 25 00:44:03 GMT 2024

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

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

Back to the top