[ 
https://issues.apache.org/jira/browse/JEXL-440?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Henri Biestro updated JEXL-440:
-------------------------------
    Description: 
*Switch / case / default Java-like behavior; statement and expression*

Switch as a +statement+ rule:
* case values must be constant (null and NaN are allowed though)
* return is allowed
* no default clause is never an issue.

Switch as +expression+  rules: 
* case values must be constant (null and NaN are allowed though)
* return is not allowed
* No strong typing means JEXL can not verify completeness of case matching at 
parsing time; a lack of default clause triggers a runtime exception if no case 
matched.

The differences between statement & expressions in a nutshell:
Statement:
{code:java}
switch (s) {
case 1: {
// some code
break;
}
case 2:
// more code, follow through to 3
case 3:
return 5; // return is allowed
}
{code}
Expression:

{code:java}
let v = switch (s) {
case 1 -> 10; 
case 2, 3 -> 20;
case 4 -> { 30 + 10 } // jexl is functional, last eval is expression value, no 
yield needed
default -> null // if not present and no case match, error
}
{code}


  was:
*Switch / case / default Java-like behavior; statement and expression*

Switch as a +statement+ rule:
* case values must be constant (null and NaN are allowed though)
* return is allowed
* no default clause is never an issue.

Switch as +expression+  rules: 
* case values must be constant (null and NaN are allowed though)
* return is not allowed
* No strong typing means JEXL can not verify completeness of case matching at 
parsing time; a lack of default clause triggers a runtime exception if no case 
matched.

The differences between statement & expressions in a nutshell:
Statement:
{code:java}
switch (s) {
case 1: {
// some code
break;
}
case 2:
// more code, follow through to 3
case 3:
return 5; // return is allowed
}
{code}
Expression:

{code:java}
let v = switch (s) {
case 1 -> 10; 
case 2, 3 -> 20;
case 4 -> { 30 + 10 } // jexl is functional, no yield needed
default -> null // if not present and no case match, error
}
{code}



> Switch statement & expressions
> ------------------------------
>
>                 Key: JEXL-440
>                 URL: https://issues.apache.org/jira/browse/JEXL-440
>             Project: Commons JEXL
>          Issue Type: New Feature
>    Affects Versions: 3.5.0
>            Reporter: Henri Biestro
>            Assignee: Henri Biestro
>            Priority: Major
>             Fix For: Later
>
>
> *Switch / case / default Java-like behavior; statement and expression*
> Switch as a +statement+ rule:
> * case values must be constant (null and NaN are allowed though)
> * return is allowed
> * no default clause is never an issue.
> Switch as +expression+  rules: 
> * case values must be constant (null and NaN are allowed though)
> * return is not allowed
> * No strong typing means JEXL can not verify completeness of case matching at 
> parsing time; a lack of default clause triggers a runtime exception if no 
> case matched.
> The differences between statement & expressions in a nutshell:
> Statement:
> {code:java}
> switch (s) {
> case 1: {
> // some code
> break;
> }
> case 2:
> // more code, follow through to 3
> case 3:
> return 5; // return is allowed
> }
> {code}
> Expression:
> {code:java}
> let v = switch (s) {
> case 1 -> 10; 
> case 2, 3 -> 20;
> case 4 -> { 30 + 10 } // jexl is functional, last eval is expression value, 
> no yield needed
> default -> null // if not present and no case match, error
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to