groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MG <mg...@arscreat.com>
Subject Re: How to find out the names of variables used in a groovy expression
Date Sun, 26 Nov 2017 20:36:46 GMT
I use Groovy as a programming, not as a script langage, so I have not 
done something like this myself, but something along the line of
http://groovyconsole.appspot.com/script/112001
should work.

On 26.11.2017 19:26, bayareagreg wrote:
> 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