Package grails.test
Class AbstractClosureProxy
- java.lang.Object
-
- groovy.lang.GroovyObjectSupport
-
- groovy.lang.Closure
-
- grails.test.AbstractClosureProxy
-
- All Implemented Interfaces:
groovy.lang.GroovyCallable,groovy.lang.GroovyObject,java.io.Serializable,java.lang.Cloneable,java.lang.Runnable,java.util.concurrent.Callable
- Direct Known Subclasses:
MockClosureProxy
public abstract class AbstractClosureProxy extends groovy.lang.ClosureSkeleton implementation of a wrapper class for closures that allows you to intercept invocations of the closure. The wrapper can be used anywhere that the target closure can be used.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractClosureProxy(groovy.lang.Closure<?> closure)Creates a new instance that wraps the target closure and sends profiling events to the given profiler log.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description groovy.lang.Closure<?>asWritable()java.lang.Objectcall(java.lang.Object... objects)This is the important one: logs entry and exit of the closure call.protected abstract groovy.lang.Closure<?>createWrapper(groovy.lang.Closure<?> c)Called when a new instance of the proxy needs to be created for the given closure.groovy.lang.Closure<?>curry(java.lang.Object... objects)protected abstract voiddoAfterCall(java.lang.Object[] args)This method is called after the target closure is invoked.protected abstract voiddoBeforeCall(java.lang.Object[] args)This method is called before the target closure is invoked.booleanequals(java.lang.Object obj)Compares based on identities, but unlike the standard implementation this one will returntrueif the given object is the target closure for this wrapper as well.java.lang.ObjectgetDelegate()intgetDirective()intgetMaximumNumberOfParameters()java.lang.Class<?>[]getParameterTypes()java.lang.ObjectgetProperty(java.lang.String property)intgetResolveStrategy()inthashCode()booleanisCase(java.lang.Object o)voidsetDelegate(java.lang.Object o)voidsetDirective(int i)voidsetProperty(java.lang.String s, java.lang.Object o)voidsetResolveStrategy(int i)-
Methods inherited from class groovy.lang.Closure
andThen, andThenSelf, andThenSelf, call, call, clone, compose, composeSelf, composeSelf, curry, dehydrate, getOwner, getThisObject, leftShift, leftShift, memoize, memoizeAtLeast, memoizeAtMost, memoizeBetween, ncurry, ncurry, rcurry, rcurry, rehydrate, rightShift, run, throwRuntimeException, trampoline, trampoline
-
-
-
-
Method Detail
-
doBeforeCall
protected abstract void doBeforeCall(java.lang.Object[] args)
This method is called before the target closure is invoked. This is a passive interceptor, so you cannot prevent the call to the target closure. You can modify the arguments, though, but it's not recommended unless you really know what you're doing.- Parameters:
args- The arguments passed to the closure.
-
doAfterCall
protected abstract void doAfterCall(java.lang.Object[] args)
This method is called after the target closure is invoked. It will be triggered whether or not an exception is thrown by the target closure.- Parameters:
args- The arguments passed to the closure.
-
createWrapper
protected abstract groovy.lang.Closure<?> createWrapper(groovy.lang.Closure<?> c)
Called when a new instance of the proxy needs to be created for the given closure. Usually the implementation simply creates a new instance of the current class, copying over the existing proxy properties:return new MyClosureProxy(c, this.field1, ...)- Parameters:
c- The closure to wrap/proxy.
-
call
public java.lang.Object call(java.lang.Object... objects)
This is the important one: logs entry and exit of the closure call.- Overrides:
callin classgroovy.lang.Closure
-
equals
public boolean equals(java.lang.Object obj)
Compares based on identities, but unlike the standard implementation this one will returntrueif the given object is the target closure for this wrapper as well.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
curry
public groovy.lang.Closure<?> curry(java.lang.Object... objects)
- Overrides:
curryin classgroovy.lang.Closure
-
isCase
public boolean isCase(java.lang.Object o)
- Overrides:
isCasein classgroovy.lang.Closure
-
asWritable
public groovy.lang.Closure<?> asWritable()
- Overrides:
asWritablein classgroovy.lang.Closure
-
getProperty
public java.lang.Object getProperty(java.lang.String property)
- Specified by:
getPropertyin interfacegroovy.lang.GroovyObject- Overrides:
getPropertyin classgroovy.lang.Closure
-
setProperty
public void setProperty(java.lang.String s, java.lang.Object o)- Specified by:
setPropertyin interfacegroovy.lang.GroovyObject- Overrides:
setPropertyin classgroovy.lang.Closure
-
getMaximumNumberOfParameters
public int getMaximumNumberOfParameters()
- Overrides:
getMaximumNumberOfParametersin classgroovy.lang.Closure
-
getParameterTypes
public java.lang.Class<?>[] getParameterTypes()
- Overrides:
getParameterTypesin classgroovy.lang.Closure
-
getDelegate
public java.lang.Object getDelegate()
- Overrides:
getDelegatein classgroovy.lang.Closure
-
setDelegate
public void setDelegate(java.lang.Object o)
- Overrides:
setDelegatein classgroovy.lang.Closure
-
getDirective
public int getDirective()
- Overrides:
getDirectivein classgroovy.lang.Closure
-
setDirective
public void setDirective(int i)
- Overrides:
setDirectivein classgroovy.lang.Closure
-
getResolveStrategy
public int getResolveStrategy()
- Overrides:
getResolveStrategyin classgroovy.lang.Closure
-
setResolveStrategy
public void setResolveStrategy(int i)
- Overrides:
setResolveStrategyin classgroovy.lang.Closure
-
-