groovy.lang
Class Closure

java.lang.Object
  extended bygroovy.lang.GroovyObjectSupport
      extended bygroovy.lang.Closure
All Implemented Interfaces:
Cloneable, GroovyObject, Runnable
Direct Known Subclasses:
IteratorClosureAdapter, MethodClosure

public abstract class Closure
extends GroovyObjectSupport
implements Cloneable, Runnable

Represents any closure object in Groovy.

Version:
$Revision: 1.53 $
Author:
James Strachan, John Wilson

Field Summary
static int DONE
           
static int SKIP
           
 
Constructor Summary
Closure(Object delegate)
           
 
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 callSpecial(Object arguments)
           
 Object clone()
           
 Closure curry(Object[] arguments)
          Support for closure currying
protected  Object doCall()
          An attempt to optimise calling closures with no parameter This method only calls doCall(Object) and will be called by call(Object) if the parameter given to call is an empty Object array
protected  Object doCall(Object p1)
          An attempt to optimise calling closures with one parameter If the closure has one untyped parameter then it will overload this function If not this will be called ans will use reflection to deal with the case of a single typed parameter
protected  Object doCall(Object p1, Object p2)
          An attempt to optimise calling closures with two parameters If the closure has two untyped parameters then it will overload this function If not this will be called ans will use reflection to deal with the case of one or two typed parameters
 Object getDelegate()
           
 int getDirective()
           
 String getMethod()
          Used when a closure wraps a method on a class
 Object getOwner()
           
 Class[] getParameterTypes()
           
 Object getProperty(String property)
           
 Object invokeMethod(String method, Object arguments)
          Invokes the given method
 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
protected static Object throwRuntimeException(Throwable throwable)
           
 
Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, setMetaClass
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DONE

public static int DONE

SKIP

public static int SKIP
Constructor Detail

Closure

public Closure(Object delegate)
Method Detail

invokeMethod

public Object invokeMethod(String method,
                           Object arguments)
Description copied from interface: GroovyObject
Invokes the given method

Specified by:
invokeMethod in interface GroovyObject
Overrides:
invokeMethod in class GroovyObjectSupport

getProperty

public Object getProperty(String property)
Specified by:
getProperty in interface GroovyObject
Overrides:
getProperty in class GroovyObjectSupport

setProperty

public void setProperty(String property,
                        Object newValue)
Description copied from interface: GroovyObject
Sets the given property to the new value

Specified by:
setProperty in interface GroovyObject
Overrides:
setProperty in class GroovyObjectSupport

isCase

public boolean isCase(Object candidate)

call

public Object call()
Invokes the closure without any parameters, returning any value if applicable.

Returns:
the value if applicable or null if there is no return statement in the closure

call

public Object call(Object arguments)
Invokes the closure, returning any value if applicable.

Parameters:
arguments - could be a single value or a List of values
Returns:
the value if applicable or null if there is no return statement in the closure

callSpecial

public Object callSpecial(Object arguments)

throwRuntimeException

protected static Object throwRuntimeException(Throwable throwable)

doCall

protected Object doCall(Object p1)
An attempt to optimise calling closures with one parameter If the closure has one untyped parameter then it will overload this function If not this will be called ans will use reflection to deal with the case of a single typed parameter

Parameters:
p1 -
Returns:
the result of calling the closure

doCall

protected Object doCall()
An attempt to optimise calling closures with no parameter This method only calls doCall(Object) and will be called by call(Object) if the parameter given to call is an empty Object array

Returns:
the result of calling the closure

doCall

protected Object doCall(Object p1,
                        Object p2)
An attempt to optimise calling closures with two parameters If the closure has two untyped parameters then it will overload this function If not this will be called ans will use reflection to deal with the case of one or two typed parameters

Parameters:
p1 -
Returns:
the result of calling the closure

getMethod

public String getMethod()
Used when a closure wraps a method on a class

Returns:
empty string

getOwner

public Object getOwner()
Returns:
the owner Object to which method calls will go which is typically the outer class when the closure is constructed

getDelegate

public Object getDelegate()
Returns:
the delegate Object to which method calls will go which is typically the outer class when the closure is constructed

setDelegate

public void setDelegate(Object delegate)
Allows the delegate to be changed such as when performing markup building

Parameters:
delegate -

getParameterTypes

public Class[] getParameterTypes()
Returns:
the parameter types of this closure

asWritable

public Closure asWritable()
Returns:
a version of this closure which implements Writable

run

public void run()
Specified by:
run in interface Runnable

curry

public Closure curry(Object[] arguments)
Support for closure currying

Parameters:
arguments -

clone

public Object clone()

getDirective

public int getDirective()
Returns:
Returns the directive.

setDirective

public void setDirective(int directive)
Parameters:
directive - The directive to set.


Copyright © 2003-2005 The Codehaus. All Rights Reserved.