[jira] [Commented] (JEXL-250) Safe navigation operator
[ https://issues.apache.org/jira/browse/JEXL-250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16353749#comment-16353749 ] Dmitri Blinov commented on JEXL-250: The following test does not pass for me {code} @Test public void test250() throws Exception { MapContext ctx = new MapContext(); HashMap
[jira] [Commented] (JEXL-250) Safe navigation operator
[ https://issues.apache.org/jira/browse/JEXL-250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16352946#comment-16352946 ] Henri Biestro commented on JEXL-250: Committed https://github.com/apache/commons-jexl/commit/dffcc160edaa1be6dbf57095e67596f9a0a89ee9 > Safe navigation operator > > > Key: JEXL-250 > URL: https://issues.apache.org/jira/browse/JEXL-250 > Project: Commons JEXL > Issue Type: New Feature >Affects Versions: 3.1 >Reporter: Dmitri Blinov >Assignee: Henri Biestro >Priority: Minor > Fix For: 3.2 > > > It would be more convenient for a script writer to have a kind of safe > navigation operator, in the form of, for example, ({{object?.property),}} for > null pointer dereferences. I think its quite a common feature of many > scripting (and compiled languages) now. The safe operator should work like > basic navigation operator for non null values and should short-circuit the > entire expression evaluation after encountering null value. > I see the difference of new operator from the existing lenient mode > evaluation in ability to explicitly define places in an expression where > {{null}} deference is allowed, for example the expression > {code}Order.Customer?.Name{code} defines that each {{Order}} should have a > {{Customer}} and only the {{Name}} of the {{Customer}} is optional. > The difference of new operator from the existing null coalescing {{??}} > operator is in its ability to short-circuit evaluation. > So, safe navigation operator would be a helpful syntaxic sugar which in my > opinion does not overlap with an existing functionality. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (JEXL-250) Safe navigation operator
[ https://issues.apache.org/jira/browse/JEXL-250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16342494#comment-16342494 ] Dmitri Blinov commented on JEXL-250: To me the idea of safe navigation is chaining of navigation operators, where one could write the one-line expression like {{Order?.Customer?.Address?.ZipCode}}, instead of cumbersome {code}var Customer = Order.Customer; if (Customer != null) {var Address = Customer.Address; ...} {code}The one-line expression should nevertheless be correctly evaluated even if some part of expression is missing. Neither null coalescing operator, nor elvis operator help me with this, but may be I just haven't figured out how to use them for this purpose. Furhermore, null coalescing operator seems not to work with undefined properties, only undefines variables, the following example {code}x = "qwerty"; (x.class1) ?? 'No such property'{code} raises {{Unsolvable property 'class1'}} > Safe navigation operator > > > Key: JEXL-250 > URL: https://issues.apache.org/jira/browse/JEXL-250 > Project: Commons JEXL > Issue Type: New Feature >Affects Versions: 3.1 >Reporter: Dmitri Blinov >Priority: Minor > > It would be more convenient for a script writer to have a kind of safe > navigation operator, in the form of, for example, ({{object?.property),}} for > null pointer dereferences. I think its quite a common feature of many > scripting (and compiled languages) now. The safe operator should work like > basic navigation operator for non null values and should short-circuit the > entire expression evaluation after encountering null value. > I see the difference of new operator from the existing lenient mode > evaluation in ability to explicitly define places in an expression where > {{null}} deference is allowed, for example the expression > {code}Order.Customer?.Name{code} defines that each {{Order}} should have a > {{Customer}} and only the {{Name}} of the {{Customer}} is optional. > The difference of new operator from the existing null coalescing {{??}} > operator is in its ability to short-circuit evaluation. > So, safe navigation operator would be a helpful syntaxic sugar which in my > opinion does not overlap with an existing functionality. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (JEXL-250) Safe navigation operator
[ https://issues.apache.org/jira/browse/JEXL-250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16342241#comment-16342241 ] Henri Biestro commented on JEXL-250: The 'null coalescing' operator '??' has been implemented and is not equivalent to the 'elvis' operator '?:'. Are you sure you need a 3rd behavior ? > Safe navigation operator > > > Key: JEXL-250 > URL: https://issues.apache.org/jira/browse/JEXL-250 > Project: Commons JEXL > Issue Type: New Feature >Affects Versions: 3.1 >Reporter: Dmitri Blinov >Priority: Minor > > It would be more convenient for a script writer to have a kind of safe > navigation operator, in the form of, for example, ({{object?.property),}} for > null pointer dereferences. I think its quite a common feature of many > scripting (and compiled languages) now. The safe operator should work like > basic navigation operator for non null values and should short-circuit the > entire expression evaluation after encountering null value. > I see the difference of new operator from the existing lenient mode > evaluation in ability to explicitly define places in an expression where > {{null}} deference is allowed, for example the expression > {code}Order.Customer?.Name{code} defines that each {{Order}} should have a > {{Customer}} and only the {{Name}} of the {{Customer}} is optional. > The difference of new operator from the existing null coalescing {{??}} > operator is in its ability to short-circuit evaluation. > So, safe navigation operator would be a helpful syntaxic sugar which in my > opinion does not overlap with an existing functionality. -- This message was sent by Atlassian JIRA (v7.6.3#76005)