Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [xtend] HowTo: Enum as a parameter in switch-case
[xtend] HowTo: Enum as a parameter in switch-case [message #664037] Thu, 07 April 2011 09:14 Go to next message
Michael L. is currently offline Michael L.
Messages: 2
Registered: April 2011
Junior Member
Hello all,

I'm having a similar problem to this thread http://www.openarchitectureware.org/forum/viewtopic.php?show topic=6880

I'd like to use an enum as a dynamic return value in a function.

Enum example:
EnumEx::ONE
EnumEx::TWO
EnumEx::THREE


Function example:
EnumEx foo() :
   let rc = new EnumEx : // I know I cannot do it like that ... it is just about explaining what I want to do
   switch {
      case x :  rc = EnumEx::ONE
      case y :  rc = EnumEx::TWO
      default :  rc = EnumEx::THREE
   } ->
   rc;


I know I cannot instantiate an enum, but how can I dynamically return enums?

Thanks in advance,
Michael.
Re: [xtend] HowTo: Enum as a parameter in switch-case [message #664056 is a reply to message #664037] Thu, 07 April 2011 10:39 Go to previous message
Michael L. is currently offline Michael L.
Messages: 2
Registered: April 2011
Junior Member
Got it!

You can do the following:

EnumEx foo() :
   let rc = 
   switch {
      case (x) :  EnumEx::ONE
      case (y) :  EnumEx::TWO
      default :  EnumEx::THREE
   } :
   rc;
Previous Topic:[Xtext2] Extending Xbase expressions
Next Topic:[Acceleo] Support for generate once
Goto Forum:
  


Current Time: Sat Oct 25 14:37:41 GMT 2014

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

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