groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bayareagreg <bayareag...@gmail.com>
Subject Re: How to find out the names of variables used in a groovy expression
Date Sun, 26 Nov 2017 18:26:27 GMT
All right, let me explain why I need this.
In my product, we let our users evaluate "custom" groovy expressions they
construct. This is done in Java via groovy Script object. There are half a
dozen "standard" product variables users can refer to in those expressions.
The values of these variables are bound into Bindings object before the
script is run. The values may be a String, a GPathResult, a java.util.Map,
etc. The problem is that some of the variables are quite expensive to
compute and it is a waste of time to do so if the expression does not
reference these variables. 
For example, if the expression happens to be "${x}", I would be nice to only
compute the value of x and bind it before invoking the script, not y, z, w,
etc.
That is why I was wondering if there was a simple way to get the list of all
variables used in an expression. Another way to solve the problem would be
some kind of "lazy evaluation" approach where we would bind all variables to
some type of "proxy" object, such that the real values are only computed on
"as needed" basis. I could not find an easy way to do that either. Some
pointers would be very much appreciated
Thanks in advance
Greg



--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html

Mime
View raw message