Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 346946

Summary: How to handle java enumerations in xtend switch statements
Product: [Tools] Xtend Reporter: Serano Colameo <serano.colameo>
Component: CoreAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED WORKSFORME QA Contact:
Severity: minor    
Priority: P3 CC: sebastian.zarnekow, sven.efftinge
Version: 2.2.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Serano Colameo CLA 2011-05-24 05:01:18 EDT
Build Identifier: Xtext 2.0.0.v201105230203

this works fine:
def getEnumType(BaseTypeEnum enumType) {
    if (enumType == BaseTypeEnum::FLOAT) {
       // ...
    }
}
		
this does not work:
def getEnumType(BaseTypeEnum enumType) {
    switch enumType {
	BaseTypeEnum::FLOAT : // (no viable alternatives at input '::')
     }
}


Reproducible: Always

Steps to Reproduce:
1. see details
2.
3.
Comment 1 Serano Colameo CLA 2011-05-24 05:01:38 EDT
workaround: use if statements instead
Comment 2 Sebastian Zarnekow CLA 2011-05-25 04:36:09 EDT
You used a type guard instead of a case. The following should work:

def getEnumType(BaseTypeEnum enumType) {
    switch enumType {
      case BaseTypeEnum::FLOAT : // note the 'case' keyword
    }
}

Please refer to the docs for details on the syntax. 

Please reopen if the switch does not work for you.
Comment 3 Serano Colameo CLA 2011-05-25 04:46:51 EDT
what about this?

def getEnumType(BaseTypeEnum enumType) {
    switch enumType {
      case BaseTypeEnum::FLOAT || BaseTypeEnum::DOUBLE : // <= not supported
      case BaseTypeEnum::FLOAT || case BaseTypeEnum::DOUBLE : // <= also not supported
    }
}

woraround:

def getEnumType(BaseTypeEnum enumType) {
     switch {
	case (enumType == BaseTypeEnum::UNSPECIFIED || enumType == BaseTypeEnum::ANY): // this works but is not so nice :-)
     }
}

thanks
serano
Comment 4 Sven Efftinge CLA 2012-01-31 06:19:56 EST
works as expected.
Comment 5 Karsten Thoms CLA 2017-09-19 17:40:07 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 6 Karsten Thoms CLA 2017-09-19 17:51:22 EDT
Closing all bugs that were set to RESOLVED before Neon.0