[
https://issues.apache.org/jira/browse/JEXL-262?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16582749#comment-16582749
]
Dmitri Blinov commented on JEXL-262:
------------------------------------
I was experimenting with this syntax myself the other day, and have an
implementation that basically works. If there is a chance for you to look into
this, please see [Github
commit|https://github.com/apache/commons-jexl/pull/5/commits/caa42b065a09e1888d0fceeaf5f9f885b04e284f].
The pull request has got littered with different commits, sorry. But the
commit itself contains only relevant changes. The idea is rather simple - the
syntax should support assigning only those properties that are already
supported by Jexl, its only a syntax sugar which uses Interpreter.setAttriute()
under the hood.
The syntax allows to specify properties, as well as nested objects properties
in the following form
{code}
bean { Property1 : "Value", 'Property2' : "Value", `Property${i}`: "Value",
[property]: "Value", nestedobj { Property1: "Value" }}
{code}
This is should be exactly equivalent to the
{code}
bean.Property1 = "Value";
bean.'Property2' = "Value";
bean.`Property${i}` = "Value";
bean[property] = "Value";
bean.nestedobj.Property1 = "Value";
bean; // The important point is that the result is the object itself, not the
last "Value"
{code}
The new syntax closely resembles already well known syntax for maps, no new
keywords here :-)
The changes to the code are rather small
> Inline object property initialization construct
> -----------------------------------------------
>
> Key: JEXL-262
> URL: https://issues.apache.org/jira/browse/JEXL-262
> Project: Commons JEXL
> Issue Type: New Feature
> Affects Versions: 3.1
> Reporter: Dmitri Blinov
> Assignee: Henri Biestro
> Priority: Minor
> Fix For: 3.1
>
>
> I wonder is it possible (not difficult) to implement in Jexl a construct that
> would allow us to initialize object properties in one statement, so that it
> would be possible to replace the code like
> {code}
> var i = Address;
> i.City = 'NY';
> i.Street = '1st Avenue';
> i.House = '22';
> return i;
> {code}
> with something like
> {code}
> Address {City : 'NY', Street : '1st Avenue', House : '22'}
> {code}
> May be we could also consider a variant for array-style accessors, like
> {code}
> var i = Address;
> i["City"] = 'NY';
> i["Street"] = '1st Avenue';
> i["House"] = '22';
> return i
> {code}
> would be identical to
> {code}
> Address {"City" : 'NY', "Street" : '1st Avenue', "House" : '22'}
> {code}
> I think this is somewhat similar to inline map initialization syntax, which
> is proved to be very useful and productive, so it would be nice to have such
> a feature for common objects too
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)