groovy.lang
Class Closure.WritableClosure

java.lang.Object
  extended by groovy.lang.GroovyObjectSupport
      extended by groovy.lang.Closure
          extended by groovy.lang.Closure.WritableClosure
All Implemented Interfaces:
GroovyObject, Writable, java.io.Serializable, java.lang.Cloneable, java.lang.Runnable
Enclosing class:
Closure

private class Closure.WritableClosure
extends Closure
implements Writable

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. This means any invokeMethod or getProperty call will be called on this inner class instead of the outer!


Field Summary
 
Fields inherited from class groovy.lang.Closure
DELEGATE_FIRST, DELEGATE_ONLY, DONE, maximumNumberOfParameters, OWNER_FIRST, OWNER_ONLY, parameterTypes, SKIP, TO_SELF
 
Constructor Summary
Closure.WritableClosure()
           
 
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 doCall(java.lang.Object[] args)
           
 boolean equals(java.lang.Object arg0)
           
 java.lang.Object getDelegate()
           
 int getMaximumNumberOfParameters()
           
 java.lang.Class[] getParameterTypes()
           
 java.lang.Object getProperty(java.lang.String property)
          Retrieves a property value.
 int getResolveStrategy()
          Gets the strategy which the closure users to resolve methods and properties
 int hashCode()
           
 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 setProperty(java.lang.String property, java.lang.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.
 java.lang.String toString()
           
 java.io.Writer writeTo(java.io.Writer out)
          writes this object to the given stream
 
Methods inherited from class groovy.lang.Closure
getDirective, getOwner, getThisObject, isCase, setDirective, throwRuntimeException
 
Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, setMetaClass
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Closure.WritableClosure

public Closure.WritableClosure()
Method Detail

writeTo

public java.io.Writer writeTo(java.io.Writer out)
                       throws java.io.IOException
Description copied from interface: Writable
writes this object to the given stream

Specified by:
writeTo in interface Writable
Throws:
java.io.IOException

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
Parameters:
method - the name of the method to call
arguments - the arguments to use for the method call
Returns:
the result of invoking the method

getProperty

public java.lang.Object getProperty(java.lang.String property)
Description copied from interface: GroovyObject
Retrieves a property value.

Specified by:
getProperty in interface GroovyObject
Overrides:
getProperty in class Closure
Parameters:
property - the name of the property of interest
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 Closure
Parameters:
property - the name of the property of interest
newValue - the new value for the property

call

public java.lang.Object call()
Description copied from class: Closure
Invokes the closure without any parameters, returning any value if applicable.

Overrides:
call in class Closure
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)
Description copied from class: Closure
Invokes the closure, returning any value if applicable.

Overrides:
call in class Closure
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

call

public java.lang.Object call(java.lang.Object[] args)
Overrides:
call in class Closure

doCall

public java.lang.Object doCall(java.lang.Object[] args)

getDelegate

public java.lang.Object getDelegate()
Overrides:
getDelegate in class Closure
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)
Description copied from class: Closure
Allows the delegate to be changed such as when performing markup building

Overrides:
setDelegate in class Closure
Parameters:
delegate - the new delegate

getParameterTypes

public java.lang.Class[] getParameterTypes()
Overrides:
getParameterTypes in class Closure
Returns:
the parameter types of the longest doCall method of this closure

getMaximumNumberOfParameters

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

asWritable

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

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class Closure

clone

public java.lang.Object clone()
Overrides:
clone in class Closure

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object arg0)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

curry

public Closure curry(java.lang.Object[] arguments)
Description copied from class: Closure
Support for closure currying

Overrides:
curry in class Closure
Parameters:
arguments - the arguments to bind
Returns:
the new closure with its arguments bound

setResolveStrategy

public void setResolveStrategy(int resolveStrategy)
Description copied from class: Closure
Sets the strategy which the closure uses to resolve property references. The default is Closure.OWNER_FIRST

Overrides:
setResolveStrategy in class Closure
Parameters:
resolveStrategy - The resolve strategy to set
See Also:
Closure.DELEGATE_FIRST, Closure.DELEGATE_ONLY, Closure.OWNER_FIRST, Closure.OWNER_ONLY, Closure.TO_SELF

getResolveStrategy

public int getResolveStrategy()
Description copied from class: Closure
Gets the strategy which the closure users to resolve methods and properties

Overrides:
getResolveStrategy in class Closure
Returns:
The resolve strategy
See Also:
Closure.DELEGATE_FIRST, Closure.DELEGATE_ONLY, Closure.OWNER_FIRST, Closure.OWNER_ONLY, Closure.TO_SELF


Copyright © ${year} The Codehaus. All Rights Reserved.