Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVT] Generic typed function
[QVT] Generic typed function [message #59803] Wed, 29 August 2007 09:40 Go to next message
Alfons Laarman is currently offline Alfons LaarmanFriend
Messages: 35
Registered: July 2009
Member
Hi everyone,

I am writing a QVT oml transformation and I have come to a problem for
which I could not find a solution. I want to create a helper function
that returns elements of the model of a certain type. But instead of
creating one function for every type in the model, I tried to be smart
and parameterized the type:

modeltype UML uses
' http://www.eclipse.org/qvt/1.0.0/Operational/examples/simple uml';
mapping main(in model: UML::Model, out o: UML::Model) {
end {
o->ownedElements += object UML::Model {
ownedElements += model.ownedElements->getType(simpleuml::Package);
}
}
}

query UML::Packageable::getPackets(in type : PrimitiveType) :
Bag(UML::Packageable) {
self->select(oclIsTypeOf(type)) --filter type
->collect(oclAsType(simpleuml::Packageable)) --cast to supertype ;
}

This does not work, because as I understand it "oclIsTypeOf" is a
language construct and therefore the argument needs to be known at
compile time. So my question is: is there any other way to do this or do
you think this is bad-practice?

Thanks for your attantion,
Regards,


Alfons
Re: [QVT] Generic typed function [message #59827 is a reply to message #59803] Wed, 29 August 2007 11:11 Go to previous message
Richard Gronback is currently offline Richard GronbackFriend
Messages: 605
Registered: July 2009
Senior Member
You're right, you cannot use oclIsTypeOf in this way. The argument needs to
be a model type, as you have in oclAsType. I think you'll need a query for
each type, or a query that has a series of conditionals. Or, skip the query
and just use select/collect for the type where you need it.

Best,
Rich


On 8/29/07 5:40 AM, in article fb3eud$tge$1@build.eclipse.org, "Alfons
Laarman" <alfons.laarman@obeo.fr> wrote:

> Hi everyone,
>
> I am writing a QVT oml transformation and I have come to a problem for
> which I could not find a solution. I want to create a helper function
> that returns elements of the model of a certain type. But instead of
> creating one function for every type in the model, I tried to be smart
> and parameterized the type:
>
> modeltype UML uses
> ' http://www.eclipse.org/qvt/1.0.0/Operational/examples/simple uml';
> mapping main(in model: UML::Model, out o: UML::Model) {
> end {
> o->ownedElements += object UML::Model {
> ownedElements += model.ownedElements->getType(simpleuml::Package);
> }
> }
> }
>
> query UML::Packageable::getPackets(in type : PrimitiveType) :
> Bag(UML::Packageable) {
> self->select(oclIsTypeOf(type)) --filter type
> ->collect(oclAsType(simpleuml::Packageable)) --cast to supertype ;
> }
>
> This does not work, because as I understand it "oclIsTypeOf" is a
> language construct and therefore the argument needs to be known at
> compile time. So my question is: is there any other way to do this or do
> you think this is bad-practice?
>
> Thanks for your attantion,
> Regards,
>
>
> Alfons
Previous Topic:Stereotype property with defined type
Next Topic:UserInteraction in Transformationprocess
Goto Forum:
  


Current Time: Sat Apr 20 00:34:37 GMT 2024

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

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

Back to the top