Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 346946 - How to handle java enumerations in xtend switch statements
Summary: How to handle java enumerations in xtend switch statements
Status: CLOSED WORKSFORME
Alias: None
Product: Xtend
Classification: Tools
Component: Core (show other bugs)
Version: 2.2.0   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-24 05:01 EDT by Serano Colameo CLA
Modified: 2017-09-19 17:51 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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