Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [MOFScript] How to specify an enumeration literal in an expression?
[MOFScript] How to specify an enumeration literal in an expression? [message #62588] Thu, 18 June 2009 11:22 Go to next message
Toñi Reina is currently offline Toñi Reina
Messages: 206
Registered: July 2009
Senior Member
Hi all,

I really don't know if this is the best group to post this question,
but since the closing of the eclipse.modelling.gmt, I don't know which
is the best group for posting it. I apologise in advance, in case this
is not the right group.

My problem is to find the right syntax for writing an expression in
which an enumeration is involved. Let's suppose you have the following
piece of metamodel described by means of KM3:

class ClassA {
attribute field: FieldType;
};
enum FieldType {
literal VALUE_A;
literal VALUE_B;
literal VALUE_C;
};

I'm trying to write a MOFScript rule to test the value stored in the
attribute field, writing something similiar to this piece of code:

metamodel.Class::method(){

if (self.field = VALUE_A){
//do something
}
}

But MOFScript does not recognize the literal VALUE_A. I also have tried
to change VALUE_A for FieldType.VALUE_A, but it doesn't work either.

The only way I have found for not having compilation errors, is the
following:

if (self.field = 0){
//do something
}

Does anybody know how to use the literals instead of the stored values
in an enumeration?

Thanks,
Toñi Reina
Re: [MOFScript] How to specify an enumeration literal in an expression? [message #62612 is a reply to message #62588] Thu, 18 June 2009 11:59 Go to previous message
Toñi Reina is currently offline Toñi Reina
Messages: 206
Registered: July 2009
Senior Member
I have just found that literals in enumerations are treated as Strings,
so the expression has to be the following one:

if (self.field = "VALUE_A"){
//do something
}



Toñi Reina Quintero escribió:
> Hi all,
>
> I really don't know if this is the best group to post this question,
> but since the closing of the eclipse.modelling.gmt, I don't know which
> is the best group for posting it. I apologise in advance, in case this
> is not the right group.
>
> My problem is to find the right syntax for writing an expression in
> which an enumeration is involved. Let's suppose you have the following
> piece of metamodel described by means of KM3:
>
> class ClassA {
> attribute field: FieldType;
> };
> enum FieldType {
> literal VALUE_A;
> literal VALUE_B;
> literal VALUE_C;
> };
>
> I'm trying to write a MOFScript rule to test the value stored in the
> attribute field, writing something similiar to this piece of code:
>
> metamodel.Class::method(){
>
> if (self.field = VALUE_A){
> //do something
> }
> }
>
> But MOFScript does not recognize the literal VALUE_A. I also have tried
> to change VALUE_A for FieldType.VALUE_A, but it doesn't work either.
>
> The only way I have found for not having compilation errors, is the
> following:
>
> if (self.field = 0){
> //do something
> }
>
> Does anybody know how to use the literals instead of the stored values
> in an enumeration?
>
> Thanks,
> Toñi Reina
Previous Topic:[Announce] M2T XPAND 0.7.0RC5 is available
Next Topic:Re: Generate Java code from UML model
Goto Forum:
  


Current Time: Sun Oct 26 08:51:55 GMT 2014

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

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