Wouldn't it be easier for you then to implement a class which extends groovy.lang.Binding which lazy evaluates your default variables and use that as your script binding instead?
On Sun, Nov 26, 2017 at 6:26 PM, bayareagreg <bayareag...@gmail.com> 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 >