Class GroovyClosure
java.lang.Object
space.jasan.support.groovy.closure.GroovyClosure
Makes Java API Groovy Closure friendly.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> groovy.lang.Closure<T>
cloneWithTopLevelOwner
(groovy.lang.Closure<T> closure) Clone with top level owner.static <T> groovy.lang.Closure<T>
cloneWithTopLevelOwner
(groovy.lang.Closure<T> closure, Object delegate) Clone with top level owner.static <T> groovy.lang.Closure<T>
cloneWithTopLevelOwner
(groovy.lang.Closure<T> closure, Object delegate, int strategy) Clone with top level owner.static Object
getPropagatedOwner
(Object object) Returns closure's owner if the object is closure or the object self otherwisestatic <T> T
setDelegate
(T potentialClosure, Object delegateWanted) Attempts to set delegate of object which might be a Closure.
-
Constructor Details
-
GroovyClosure
public GroovyClosure()
-
-
Method Details
-
setDelegate
Attempts to set delegate of object which might be a Closure.This usually happens when the object is functional interface or single abstract method class. Only the first use case is supported at the moment.
The possibility of delegate being set should be documented with @DelegatesTo annotation (use provided scope to groovy dependency to retain the annotation to Groovy enabled projects).
- Type Parameters:
T
- the type of the object which might be backed by Groovy closure- Parameters:
potentialClosure
- object which might be backed by Groovy closuredelegateWanted
- delegate to be set if the object is backed by Groovy closure- Returns:
- always the original potentialClosure parameter which might have the delegate set if possible
-
getPropagatedOwner
Returns closure's owner if the object is closure or the object self otherwise- Parameters:
object
- maybe a closure- Returns:
- closure's owner if the object is closure or the object self otherwise
-
cloneWithTopLevelOwner
public static <T> groovy.lang.Closure<T> cloneWithTopLevelOwner(groovy.lang.Closure<T> closure) Clone with top level owner.- Type Parameters:
T
- the closure type- Parameters:
closure
- the closure- Returns:
- the returned closure
-
cloneWithTopLevelOwner
public static <T> groovy.lang.Closure<T> cloneWithTopLevelOwner(groovy.lang.Closure<T> closure, Object delegate) Clone with top level owner.- Type Parameters:
T
- the closure type- Parameters:
closure
- the closuredelegate
- the delegate- Returns:
- the returned closure
-
cloneWithTopLevelOwner
public static <T> groovy.lang.Closure<T> cloneWithTopLevelOwner(groovy.lang.Closure<T> closure, Object delegate, int strategy) Clone with top level owner.- Type Parameters:
T
- the closure type- Parameters:
closure
- the closuredelegate
- the delegatestrategy
- the strategy- Returns:
- the returned closure
-