Java Code Examples for groovy.lang.Closure#curry()

The following examples show how to use groovy.lang.Closure#curry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StreamingJsonBuilder.java    From groovy with Apache License 2.0 5 votes vote down vote up
private static void curryDelegateAndGetContent(Writer w, @DelegatesTo(StreamingJsonDelegate.class) Closure c, Object o, boolean first, JsonGenerator generator) {
    StreamingJsonDelegate delegate = new StreamingJsonDelegate(w, first, generator);
    Closure curried = c.curry(o);
    curried.setDelegate(delegate);
    curried.setResolveStrategy(Closure.DELEGATE_FIRST);
    curried.call();
}
 
Example 2
Source File: JsonDelegate.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Factory method for creating <code>JsonDelegate</code>s from closures currying an object
 * argument.
 *
 * @param c closure representing JSON objects
 * @param o an object curried to the closure
 * @return an instance of <code>JsonDelegate</code>
 */
public static Map<String, Object> curryDelegateAndGetContent(Closure<?> c, Object o) {
    JsonDelegate delegate = new JsonDelegate();
    Closure<?> curried = c.curry(o);
    curried.setDelegate(delegate);
    curried.setResolveStrategy(Closure.DELEGATE_FIRST);
    curried.call();

    return delegate.getContent();
}