public abstract class Closure extends GroovyObjectSupport implements java.lang.Cloneable, java.lang.Runnable
def a = 1 def c = {a} assert c() == 1To 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
|
protected java.lang.Class[] |
parameterTypes |
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)
Retrieves a property value.
|
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, setMetaClass
public 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 java.lang.Class[] parameterTypes
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_SELF
public int getResolveStrategy()
DELEGATE_FIRST
,
DELEGATE_ONLY
,
OWNER_FIRST
,
OWNER_ONLY
,
TO_SELF
public java.lang.Object getThisObject()
public java.lang.Object getProperty(java.lang.String property)
GroovyObject
getProperty
in interface GroovyObject
getProperty
in class GroovyObjectSupport
property
- the name of the property of interestpublic void setProperty(java.lang.String property, java.lang.Object newValue)
GroovyObject
setProperty
in interface GroovyObject
setProperty
in class GroovyObjectSupport
property
- the name of the property of interestnewValue
- the new value for the propertypublic 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.Runnable
public Closure curry(java.lang.Object[] arguments)
arguments
- the arguments to bindpublic java.lang.Object clone()
clone
in class java.lang.Object
public int getDirective()
public void setDirective(int directive)
directive
- The directive to set.