Groovy allows instances of Closures to be called in a short form. For example:
def a = 1
def c = { a }
assert c() == 1
To be able to use a Closure in this way with your own
subclass, you need to provide a doCall method with any
signature you want to. This ensures that
getMaximumNumberOfParameters() and
getParameterTypes() will work too without any
additional code. If no doCall method is provided a
closure must be used in its long form like
def a = 1
def c = {a}
assert c.call() == 1
| Modifier and Type | Class and Description |
|---|---|
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private BooleanClosureWrapper | |
| private Object | |
| public static final int | DELEGATE_FIRST
With this resolveStrategy set the closure will attempt to resolve property references and methods to the delegate first then the owner. |
| public static final int | DELEGATE_ONLY
With this resolveStrategy set the closure will resolve property references and methods to the delegate only and entirely bypass the owner. |
| private int | |
| public static final int | |
| private static final Object[] | |
| public static final Closure | |
| protected int | |
| private Object | |
| public static final int | OWNER_FIRST
With this resolveStrategy set the closure will attempt to resolve property references and methods to the owner first, then the delegate (this is the default strategy). |
| public static final int | OWNER_ONLY
With this resolveStrategy set the closure will resolve property references and methods to the owner only and not call the delegate at all. |
| protected Class | |
| private int | |
| private static final long | |
| public static final int | |
| private Object | |
| public static final int | TO_SELF
With this resolveStrategy set the closure will resolve property references to itself and go through the usual MetaClass look-up process. |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public <W> Closure | |
| public Closure | |
| public Closure | Returns: the newly composed closurethe number of times to reverse compose the closure with itself times)Call |
| public Closure | Returns: a version of this closure which implements Writable. Note that the returned Writable also overridestoString() in order
to allow rendering the result directly to a String.
|
| public V | Returns: The value if applicable or null if there is no return statement in the closure.Implements java. |
| public V | |
| public V | |
| public Object | |
| public Closure | |
| public Closure | |
| public Closure | Returns: the newly composed closurethe number of times to compose the closure with itself times)Call |
| public Closure | |
| public Closure | |
| public Closure | Returns: a serializable closure.Returns a copy of this closure where the "owner", "delegate" and "thisObject" fields are null, allowing proper serialization when one of them is not serializable. |
| public Object | Returns: the delegate Object to which method calls will go which is typically the outer class when the closure is constructed
|
| public int | |
| public int | Returns: the maximum number of parameters a doCall method of this closure can take
|
| public Object | Returns: the owner Object to which method calls will go which is typically the outer class when the closure is constructed
|
| public Class | |
| public Object | getProperty(final String
the name of the property of interest property)Overrides default groovy. |
| private Object | |
| private Object | |
| private Object | |
| public int | Returns: The resolve strategyGets the strategy which the closure uses to resolve methods and properties |
| public Object | |
| public boolean | |
| public Closure | |
| public V | |
| public Closure | Returns: A new closure forwarding to the original one while caching the resultsCreates a caching variant of the closure. |
| public Closure | Returns: A new function forwarding to the original one while caching the resultsNumber of cached return values to protect from garbage collection protectedCacheSize)Creates a caching variant of the closure with automatic cache size adjustment and lower limit on the cache size. |
| public Closure | Returns: A new function forwarding to the original one while caching the resultsThe maximum size the cache can grow to maxCacheSize)Creates a caching variant of the closure with upper limit on the cache size. |
| public Closure | Returns: A new function forwarding to the original one while caching the resultsNumber of cached return values to protect from garbage collection protectedCacheSize, final int The maximum size the cache can grow to maxCacheSize)Creates a caching variant of the closure with automatic cache size adjustment and lower and upper limits on the cache size. |
| public Closure | |
| public Closure | |
| public Closure | |
| public Closure | |
| public Closure | Returns: a copy of this closure where owner, delegate and thisObject are replacedthe closure delegate delegate, Object the closure owner owner, Object the closure "this" object thisObject)Returns a copy of this closure for which the delegate, owner and thisObject are replaced with the supplied parameters. |
| public <W> Closure | Returns: the new composed Closurethe Closure to compose with the current Closure other)Support for Closure forward composition. |
| public void | |
| public void | setDelegate(Object
the new delegate delegate)Allows the delegate to be changed such as when performing markup building |
| public void | |
| public void | setProperty(String
the name of the property of interest property, Object the new value for the property newValue)Overrides default groovy. |
| private void | |
| private void | |
| private void | |
| public void | setResolveStrategy(int
The resolve strategy to set resolveStrategy)Sets the strategy which the closure uses to resolve property references and methods. |
| protected static Object | |
| public Closure | Returns: A closure, which will execute the original closure on a trampoline.Parameters to the closure, so as the trampoline mechanism can call it args)Builds a trampolined variant of the current closure. |
| public Closure | Returns: A closure, which will execute the original closure on a trampoline.Builds a trampolined variant of the current closure. |