groovy.lang
Class Closure

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

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

Represents any closure object in Groovy.

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

Field Summary
static int DONE
           
protected  int maximumNumberOfParameters
           
static int SKIP
           
 
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)
           
protected  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
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

maximumNumberOfParameters

protected int maximumNumberOfParameters

DONE

public static final int DONE
See Also:
Constant Field Values

SKIP

public static final int SKIP
See Also:
Constant Field Values
Constructor Detail

Closure

public Closure(java.lang.Object owner,
               java.lang.Object thisObject)

Closure

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

getThisObject

protected java.lang.Object getThisObject()

getProperty

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

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

isCase

public boolean isCase(java.lang.Object candidate)

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[] args)

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)

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 the longest doCall method of this closure

getMaximumNumberOfParameters

public int getMaximumNumberOfParameters()
Returns:
the maximum number of parameters a doCall methos of this closure can take

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()
Overrides:
clone in class java.lang.Object

getDirective

public int getDirective()
Returns:
Returns the directive.

setDirective

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


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