|
|||||||||
| 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() == 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
| Field Summary | |
|---|---|
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 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 Summary | |
|---|---|
Closure(Object owner)
|
|
Closure(Object owner,
Object thisObject)
|
|
| Method Summary | |
|---|---|
Closure |
asWritable()
|
Object |
call()
Invokes the closure without any parameters, returning any value if applicable. |
Object |
call(Object arguments)
Invokes the closure, returning any value if applicable. |
Object |
call(Object[] args)
|
Object |
clone()
|
Closure |
curry(Object[] arguments)
Support for closure currying |
Object |
getDelegate()
|
int |
getDirective()
|
int |
getMaximumNumberOfParameters()
|
Object |
getOwner()
|
Class[] |
getParameterTypes()
|
Object |
getProperty(String property)
Retrieves a property value. |
int |
getResolveStrategy()
Gets the strategy which the closure users to resolve methods and properties |
Object |
getThisObject()
|
boolean |
isCase(Object candidate)
|
void |
run()
|
void |
setDelegate(Object delegate)
Allows the delegate to be changed such as when performing markup building |
void |
setDirective(int directive)
|
void |
setProperty(String property,
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 Object |
throwRuntimeException(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
protected Class[] parameterTypes
protected int maximumNumberOfParameters
| Constructor Detail |
|---|
public Closure(Object owner,
Object thisObject)
public Closure(Object owner)
| Method Detail |
|---|
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 Object getThisObject()
public Object getProperty(String property)
GroovyObject
getProperty in interface GroovyObjectgetProperty in class GroovyObjectSupportproperty - the name of the property of interest
public void setProperty(String property,
Object newValue)
GroovyObject
setProperty in interface GroovyObjectsetProperty in class GroovyObjectSupportproperty - the name of the property of interestnewValue - the new value for the propertypublic boolean isCase(Object candidate)
public Object call()
public Object call(Object[] args)
public Object call(Object arguments)
arguments - could be a single value or a List of values
protected static Object throwRuntimeException(Throwable throwable)
public Object getOwner()
public Object getDelegate()
public void setDelegate(Object delegate)
delegate - the new delegatepublic Class[] getParameterTypes()
public int getMaximumNumberOfParameters()
public Closure asWritable()
Object.toString() in order
to allow rendering the result directly to a String.public void run()
run in interface Runnablepublic Closure curry(Object[] arguments)
arguments - the arguments to bind
public Object clone()
clone in class Objectpublic int getDirective()
public void setDirective(int directive)
directive - The directive to set.
|
Copyright © 2003-2009 The Codehaus. All rights reserved. | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||