Package grails.test

Class 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.Closure
    Skeleton 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
    • Field Summary

      • Fields inherited from class groovy.lang.Closure

        DELEGATE_FIRST, DELEGATE_ONLY, DONE, IDENTITY, maximumNumberOfParameters, OWNER_FIRST, OWNER_ONLY, parameterTypes, SKIP, TO_SELF
    • 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.Object call​(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 void doAfterCall​(java.lang.Object[] args)
      This method is called after the target closure is invoked.
      protected abstract void doBeforeCall​(java.lang.Object[] args)
      This method is called before the target closure is invoked.
      boolean equals​(java.lang.Object obj)
      Compares based on identities, but unlike the standard implementation this one will return true if the given object is the target closure for this wrapper as well.
      java.lang.Object getDelegate()  
      int getDirective()  
      int getMaximumNumberOfParameters()  
      java.lang.Class<?>[] getParameterTypes()  
      java.lang.Object getProperty​(java.lang.String property)  
      int getResolveStrategy()  
      int hashCode()  
      boolean isCase​(java.lang.Object o)  
      void setDelegate​(java.lang.Object o)  
      void setDirective​(int i)  
      void setProperty​(java.lang.String s, java.lang.Object o)  
      void setResolveStrategy​(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
      • Methods inherited from class groovy.lang.GroovyObjectSupport

        getMetaClass, setMetaClass
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface groovy.lang.GroovyObject

        invokeMethod
    • Constructor Detail

      • AbstractClosureProxy

        public AbstractClosureProxy​(groovy.lang.Closure<?> closure)
        Creates a new instance that wraps the target closure and sends profiling events to the given profiler log.
        Parameters:
        closure - The target closure to wrap.
    • 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:
        call in class groovy.lang.Closure
      • equals

        public boolean equals​(java.lang.Object obj)
        Compares based on identities, but unlike the standard implementation this one will return true if the given object is the target closure for this wrapper as well.
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

        public groovy.lang.Closure<?> curry​(java.lang.Object... objects)
        Overrides:
        curry in class groovy.lang.Closure
      • isCase

        public boolean isCase​(java.lang.Object o)
        Overrides:
        isCase in class groovy.lang.Closure
      • asWritable

        public groovy.lang.Closure<?> asWritable()
        Overrides:
        asWritable in class groovy.lang.Closure
      • getProperty

        public java.lang.Object getProperty​(java.lang.String property)
        Specified by:
        getProperty in interface groovy.lang.GroovyObject
        Overrides:
        getProperty in class groovy.lang.Closure
      • setProperty

        public void setProperty​(java.lang.String s,
                                java.lang.Object o)
        Specified by:
        setProperty in interface groovy.lang.GroovyObject
        Overrides:
        setProperty in class groovy.lang.Closure
      • getMaximumNumberOfParameters

        public int getMaximumNumberOfParameters()
        Overrides:
        getMaximumNumberOfParameters in class groovy.lang.Closure
      • getParameterTypes

        public java.lang.Class<?>[] getParameterTypes()
        Overrides:
        getParameterTypes in class groovy.lang.Closure
      • getDelegate

        public java.lang.Object getDelegate()
        Overrides:
        getDelegate in class groovy.lang.Closure
      • setDelegate

        public void setDelegate​(java.lang.Object o)
        Overrides:
        setDelegate in class groovy.lang.Closure
      • getDirective

        public int getDirective()
        Overrides:
        getDirective in class groovy.lang.Closure
      • setDirective

        public void setDirective​(int i)
        Overrides:
        setDirective in class groovy.lang.Closure
      • getResolveStrategy

        public int getResolveStrategy()
        Overrides:
        getResolveStrategy in class groovy.lang.Closure
      • setResolveStrategy

        public void setResolveStrategy​(int i)
        Overrides:
        setResolveStrategy in class groovy.lang.Closure