| Summary: | How to handle java enumerations in xtend switch statements | ||
|---|---|---|---|
| Product: | [Tools] Xtend | Reporter: | Serano Colameo <serano.colameo> |
| Component: | Core | Assignee: | 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: | |||
workaround: use if statements instead 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.
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
works as expected. Closing all bugs that were set to RESOLVED before Neon.0 Closing all bugs that were set to RESOLVED before Neon.0 |
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.