|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgroovy.lang.GroovyObjectSupport
groovy.lang.Closure
public abstract class Closure
Represents any closure object in Groovy.
Groovy allows instances of Closures to be called in a short form. For example: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
Nested Class Summary | |
---|---|
private class |
Closure.WritableClosure
Implementation note: This has to be an inner class! Reason: Closure.this.call will call the outer call method, but with the inner class as executing object. |
Field Summary | |
---|---|
private java.lang.Object |
delegate
|
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 |
private int |
directive
|
static int |
DONE
|
private static java.lang.Object[] |
EMPTY_OBJECT_ARRAY
|
protected int |
maximumNumberOfParameters
|
private java.lang.Object |
owner
|
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
|
private int |
resolveStrategy
|
static int |
SKIP
|
private java.lang.Object |
thisObject
|
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 Summary | |
---|---|
Closure(java.lang.Object owner)
|
|
Closure(java.lang.Object owner,
java.lang.Object thisObject)
|
Method Summary | |
---|---|
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. |
private java.lang.Object |
getPropertyDelegateFirst(java.lang.String property)
|
private java.lang.Object |
getPropertyOwnerFirst(java.lang.String property)
|
private java.lang.Object |
getPropertyTryThese(java.lang.String property,
java.lang.Object firstTry,
java.lang.Object secondTry)
|
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. |
private void |
setPropertyDelegateFirst(java.lang.String property,
java.lang.Object newValue)
|
private void |
setPropertyOwnerFirst(java.lang.String property,
java.lang.Object newValue)
|
private void |
setPropertyTryThese(java.lang.String property,
java.lang.Object newValue,
java.lang.Object firstTry,
java.lang.Object secondTry)
|
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)
|
Methods inherited from class groovy.lang.GroovyObjectSupport |
---|
getMetaClass, invokeMethod, setMetaClass |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
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
public static final int DONE
public static final int SKIP
private static final java.lang.Object[] EMPTY_OBJECT_ARRAY
private java.lang.Object delegate
private java.lang.Object owner
private java.lang.Object thisObject
private int resolveStrategy
private int directive
protected java.lang.Class[] parameterTypes
protected int maximumNumberOfParameters
Constructor Detail |
---|
public Closure(java.lang.Object owner, java.lang.Object thisObject)
public Closure(java.lang.Object owner)
Method Detail |
---|
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 interest
private java.lang.Object getPropertyDelegateFirst(java.lang.String property)
private java.lang.Object getPropertyTryThese(java.lang.String property, java.lang.Object firstTry, java.lang.Object secondTry)
private java.lang.Object getPropertyOwnerFirst(java.lang.String property)
public 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 propertyprivate void setPropertyDelegateFirst(java.lang.String property, java.lang.Object newValue)
private void setPropertyTryThese(java.lang.String property, java.lang.Object newValue, java.lang.Object firstTry, java.lang.Object secondTry)
private void setPropertyOwnerFirst(java.lang.String property, java.lang.Object newValue)
public 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 values
protected 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 bind
public java.lang.Object clone()
clone
in class java.lang.Object
public int getDirective()
public void setDirective(int directive)
directive
- The directive to set.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |