groovy.lang
Class Closure

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

public abstract class Closure
extends GroovyObjectSupport
implements java.lang.Cloneable, java.lang.Runnable

Represents any closure object in Groovy.

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

Nested Class Summary
private  class Closure.WritableClosure
           
 
Field Summary
private  java.lang.Object[] curriedParams
           
private  java.lang.Object delegate
           
private  int directive
           
private  java.lang.reflect.Method doCallMethod
           
static int DONE
           
private static java.lang.Object[] emptyArray
           
private static java.lang.Object[] emptyArrayParameter
           
private static java.lang.Object[] noParameters
           
private  int numberOfParameters
           
private  java.lang.Object owner
           
private  java.lang.Class[] parameterTypes
           
static int SKIP
           
private  boolean supportsVarargs
           
 
Fields inherited from class groovy.lang.GroovyObjectSupport
 
Constructor Summary
Closure(java.lang.Object delegate)
           
 
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.
private  java.lang.Object callViaReflection(java.lang.Object[] params)
           
 java.lang.Object clone()
           
 Closure curry(java.lang.Object[] arguments)
          Support for closure currying
protected  java.lang.Object doCall(java.lang.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  java.lang.Object doCall(java.lang.Object p1, java.lang.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
 java.lang.Object getDelegate()
           
 int getDirective()
           
 java.lang.String getMethod()
          Used when a closure wraps a method on a class
 java.lang.Object getOwner()
           
 java.lang.Class[] getParameterTypes()
           
 java.lang.Object getProperty(java.lang.String property)
           
 java.lang.Object invokeMethod(java.lang.String method, java.lang.Object arguments)
          Invokes the given method
 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
protected static java.lang.Object throwRuntimeException(java.lang.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

noParameters

private static final java.lang.Object[] noParameters

emptyArray

private static final java.lang.Object[] emptyArray

emptyArrayParameter

private static final java.lang.Object[] emptyArrayParameter

delegate

private java.lang.Object delegate

owner

private final java.lang.Object owner

doCallMethod

private final java.lang.reflect.Method doCallMethod

supportsVarargs

private final boolean supportsVarargs

parameterTypes

private final java.lang.Class[] parameterTypes

numberOfParameters

private final int numberOfParameters

curriedParams

private java.lang.Object[] curriedParams

directive

private int directive

DONE

public static int DONE

SKIP

public static int SKIP
Constructor Detail

Closure

public Closure(java.lang.Object delegate)
Method Detail

invokeMethod

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

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

getProperty

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

setProperty

public void setProperty(java.lang.String property,
                        java.lang.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

call

public java.lang.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 java.lang.Object call(java.lang.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

throwRuntimeException

protected static java.lang.Object throwRuntimeException(java.lang.Throwable throwable)

doCall

protected java.lang.Object doCall(java.lang.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 java.lang.Object doCall(java.lang.Object p1,
                                  java.lang.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

callViaReflection

private java.lang.Object callViaReflection(java.lang.Object[] params)

getMethod

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

Returns:
empty string

getOwner

public java.lang.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 java.lang.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(java.lang.Object delegate)
Allows the delegate to be changed such as when performing markup building

Parameters:
delegate -

getParameterTypes

public java.lang.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 java.lang.Runnable

curry

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

Parameters:
arguments -

clone

public java.lang.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.