|
Re: [QVT] Generic typed function [message #59827 is a reply to message #59803] |
Wed, 29 August 2007 11:11 |
Richard Gronback 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
|
|
|
Powered by
FUDForum. Page generated in 0.02750 seconds