public abstract class Closure extends GroovyObjectSupport implements java.lang.Cloneable, java.lang.Runnable
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 | Field and Description |
|---|---|
static int |
DELEGATE_FIRST
With this resolveStrategy set the closure will attempt to resolve property references to the
delegate first
|
static int |
DELEGATE_ONLY
With this resolveStrategy set the closure will resolve property references to the delegate
only and entirely bypass the owner
|
static int |
DONE |
protected int |
maximumNumberOfParameters |
static int |
OWNER_FIRST
With this resolveStrategy set the closure will attempt to resolve property references to the
owner first
|
static int |
OWNER_ONLY
With this resolveStrategy set the closure will resolve property references to the owner only
and not call the delegate at all
|
static int |
SKIP |
static int |
TO_SELF
With this resolveStrategy set the closure will resolve property references to itself and go
through the usual MetaClass look-up process.
|
| Constructor and Description |
|---|
Closure(java.lang.Object owner) |
Closure(java.lang.Object owner,
java.lang.Object thisObject) |
| Modifier and Type | Method and Description |
|---|---|
Closure |
asWritable() |
java.lang.Object |
call()
Invokes the closure without any parameters, returning any value if applicable.
|
java.lang.Object |
call(java.lang.Object arguments)
Invokes the closure, returning any value if applicable.
|
java.lang.Object |
call(java.lang.Object[] args) |
java.lang.Object |
clone() |
Closure |
curry(java.lang.Object[] arguments)
Support for closure currying
|
java.lang.Object |
getDelegate() |
int |
getDirective() |
int |
getMaximumNumberOfParameters() |
java.lang.Object |
getOwner() |
java.lang.Class[] |
getParameterTypes() |
java.lang.Object |
getProperty(java.lang.String property) |
int |
getResolveStrategy()
Gets the strategy which the closure users to resolve methods and properties
|
java.lang.Object |
getThisObject() |
boolean |
isCase(java.lang.Object candidate) |
void |
run() |
void |
setDelegate(java.lang.Object delegate)
Allows the delegate to be changed such as when performing markup building
|
void |
setDirective(int directive) |
void |
setProperty(java.lang.String property,
java.lang.Object newValue)
Sets the given property to the new value
|
void |
setResolveStrategy(int resolveStrategy)
Sets the strategy which the closure uses to resolve property references.
|
protected static java.lang.Object |
throwRuntimeException(java.lang.Throwable throwable) |
getMetaClass, invokeMethod, setMetaClasspublic static final int OWNER_FIRST
public static final int DELEGATE_FIRST
public static final int OWNER_ONLY
public static final int DELEGATE_ONLY
public static final int TO_SELF
protected int maximumNumberOfParameters
public static final int DONE
public static final int SKIP
public Closure(java.lang.Object owner,
java.lang.Object thisObject)
public Closure(java.lang.Object owner)
public void setResolveStrategy(int resolveStrategy)
resolveStrategy - The resolve strategy to setDELEGATE_FIRST,
DELEGATE_ONLY,
OWNER_FIRST,
OWNER_ONLY,
TO_SELFpublic int getResolveStrategy()
DELEGATE_FIRST,
DELEGATE_ONLY,
OWNER_FIRST,
OWNER_ONLY,
TO_SELFpublic java.lang.Object getThisObject()
public java.lang.Object getProperty(java.lang.String property)
getProperty in interface GroovyObjectgetProperty in class GroovyObjectSupportpublic void setProperty(java.lang.String property,
java.lang.Object newValue)
GroovyObjectsetProperty in interface GroovyObjectsetProperty in class GroovyObjectSupportpublic boolean isCase(java.lang.Object candidate)
public java.lang.Object call()
public java.lang.Object call(java.lang.Object[] args)
public java.lang.Object call(java.lang.Object arguments)
arguments - could be a single value or a List of valuesprotected static java.lang.Object throwRuntimeException(java.lang.Throwable throwable)
public java.lang.Object getOwner()
public java.lang.Object getDelegate()
public void setDelegate(java.lang.Object delegate)
delegate - the new delegatepublic java.lang.Class[] getParameterTypes()
public int getMaximumNumberOfParameters()
public Closure asWritable()
public void run()
run in interface java.lang.Runnablepublic Closure curry(java.lang.Object[] arguments)
arguments - the arguments to bindpublic java.lang.Object clone()
clone in class java.lang.Objectpublic int getDirective()
public void setDirective(int directive)
directive - The directive to set.