Skip to main content



      Home
Home » Archived » M2M (model-to-model transformation) » [QVTo] Access EMF model enum value
[QVTo] Access EMF model enum value [message #543841] Wed, 30 June 2010 13:59 Go to next message
Eclipse UserFriend
I've got a transform from one EMF model to another. I have an EMF enum (say days of the week, Sunday =0, etc.), and in the transform, I need access to the integer value of the enum. How do I access this in the qvto transform?
Re: [QVTo] Access EMF model enum value [message #544092 is a reply to message #543841] Thu, 01 July 2010 10:51 Go to previous messageGo to next message
Eclipse UserFriend
So I've figured a way around the lack of this feature, but it introduces the possibility of errors during maintenance because the int value is now defined in two locations instead of one

query CALENDAR::Day::intValue() : Integer {
    var value : Integer := 0;

    switch {
        case (self = Day::Sunday) value := 0;
        case (self = Day::Monday) value := 1;
        case (self = Day::Tuesday) value :=2;
        .
        .
        .
    };

    return value;
}


Anyone have a better idea?
Re: [QVTo] Access EMF model enum value [message #544529 is a reply to message #543841] Sat, 03 July 2010 08:00 Go to previous messageGo to next message
Eclipse UserFriend
I've assumed WeekDay::Sarurday is instance of Ecore::EEnumLiteral, but without success.
modeltype EcoreMM "strict" uses ecore('http://www.eclipse.org/emf/2002/Ecore');
// ...
var eEnumLiteral : EEnumLiteral := myClass.myAttribute.oclAsType(EcoreMM::EEnumLiteral);
log(eEnumLiteral.value.toString());


The output is "<Invalid>" Sad

Ciao
Olli
Re: [QVTo] Access EMF model enum value [message #544551 is a reply to message #543841] Sat, 03 July 2010 11:45 Go to previous messageGo to next message
Eclipse UserFriend
Thank Olli, that's along the lines of what I was looking for, a shame it doesn't work. It looks like what you came up with would be closer to a real solution. Yes, it's an EEnumLiteral.
Re: [QVTo] Access EMF model enum value [message #544577 is a reply to message #543841] Sun, 04 July 2010 03:48 Go to previous messageGo to next message
Eclipse UserFriend
A partial success:
var eEnum : EEnum := TestMM::WeekDay.oclAsType(EcoreMM::EEnum);
log(eEnum.getEEnumLiteralByLiteral("saturday").value.toString());


WeekDay:Sturday is not instance of EEnumLiteral but WeekDay is instance of EEnumerator.

So only a partial solution, becouse I don't have an idea, to get the literal string of the WeekDay:Sturday.

Ciao
Olli

Re: [QVTo] Access EMF model enum value [message #548159 is a reply to message #544577] Tue, 20 July 2010 16:43 Go to previous message
Eclipse UserFriend
log(eEnum.getEEnumLiteralByLiteral(self.weekday.repr()).value.toString());


That seems to work. I'm curious what "self.weekday.repr()" returns, the name or the literal? And does it pull that representation out of the model, or out of your translated .properties files?
Previous Topic:Transformation between UML Profiles
Next Topic:[Xtend] Problem with a specific transformation
Goto Forum:
  


Current Time: Mon Jun 16 15:51:23 EDT 2025

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

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

Back to the top