Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » Transformations between enums in QVTo
Transformations between enums in QVTo [message #874933] Mon, 21 May 2012 20:28 Go to next message
n_uu_b Missing name is currently offline n_uu_b Missing nameFriend
Messages: 5
Registered: August 2011
Junior Member
Hi,

I have a basic doubt about how can I make transformations between Enumerations,
e.g,
my source metamodel has a enum A with literals "a1" and "a2" and my target has a enum B with literals "b1" and "b2".

mapping A::A2B() : B{
B::b1 := A::a1; //It doesnt work
B2 := self.a2; //And it also doesnt work
}

So, how can I make this transformation correctly?

Thanks.
Re: Transformations between enums in QVTo [message #874951 is a reply to message #874933] Mon, 21 May 2012 21:03 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7106
Registered: July 2009
Senior Member
Hi

Try writing a Java Enum to Enum mapping and then you'll understand why
what you've written is daft.

Regards

Ed Willink

On 21/05/2012 21:28, n_uu_b Mising name wrote:
> Hi,
>
> I have a basic doubt about how can I make transformations between
> Enumerations, e.g, my source metamodel has a enum A with literals "a1"
> and "a2" and my target has a enum B with literals "b1" and "b2".
>
> mapping A::A2B() : B{
> B::b1 := A::a1; //It doesnt work
> B2 := self.a2; //And it also doesnt work
> }
>
> So, how can I make this transformation correctly?
>
> Thanks.
Re: Transformations between enums in QVTo [message #875167 is a reply to message #874933] Tue, 22 May 2012 09:03 Go to previous messageGo to next message
Eclipse UserFriend
On 21.05.2012 22:28, n_uu_b Mising name wrote:
> I have a basic doubt about how can I make transformations between
> Enumerations, e.g, my source metamodel has a enum A with literals "a1"
> and "a2" and my target has a enum B with literals "b1" and "b2".

query SOURCE::A::toExt() : TARGET::B
{
return switch {
case (self = SOURCE::A::a1) TARGET::B::b1;
case (self = SOURCE::A::a2) TARGET::B::b2;
else assert error (false) with log("Illegal enum value");
}
}

That's how I usually do it. In your mapping you can then just type

dstEnumAttrib := self.srcEnumAttrib.toExt();

I'm sure the "assert error" thing can be optimized, but I don't know how
and it works that way for me.

Regards
Marius
Re: Transformations between enums in QVTo [message #875394 is a reply to message #875167] Tue, 22 May 2012 17:02 Go to previous message
n_uu_b Missing name is currently offline n_uu_b Missing nameFriend
Messages: 5
Registered: August 2011
Junior Member
Thanks Marius, I used that query for my enums and it works perfectly Smile
I was wrong trying to create a mapping to transform enums.
Thanks again
Previous Topic:[QVTO] Default initialization of * features
Next Topic:1:m mappings / avoid traces
Goto Forum:
  


Current Time: Wed Apr 21 17:32:10 GMT 2021

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

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

Back to the top