public ClosureBlueprint(Closure closure, Object subject) { this.closure = closure; this.subject = subject; closure.setResolveStrategy(Closure.DELEGATE_ONLY); }
public void setResolveStrategy(int resolveStrategy) { ((Closure) getOwner()).setResolveStrategy(resolveStrategy); second.setResolveStrategy(resolveStrategy); }
@Override public void $setDelegate(Object delegate) { closure.setResolveStrategy(Closure.DELEGATE_FIRST); closure.setDelegate(delegate); } };
public void setUpdate(Closure update) { if (update != null) { update.setDelegate(this); update.setResolveStrategy(Closure.DELEGATE_FIRST); } this.update = update; }
public void setResolveStrategy(int resolveStrategy) { ((Closure) getOwner()).setResolveStrategy(resolveStrategy); }
@Override public boolean onNodeChildren(final FactoryBuilderSupport builder, final Object node, final Closure childContent) { if (node instanceof SecureASTCustomizer) { Closure clone = (Closure) childContent.clone(); clone.setDelegate(node); clone.setResolveStrategy(Closure.DELEGATE_FIRST); clone.call(); } return false; } }
@SuppressWarnings("unchecked") public <R> R withTypeChecker(Closure<R> code) { Closure<R> clone = (Closure<R>) code.clone(); clone.setDelegate(typeCheckingVisitor); clone.setResolveStrategy(Closure.DELEGATE_FIRST); return clone.call(); }
public void define(Class subClass, Closure closure) { final SubClassDefiningClosure definer = new SubClassDefiningClosure(subClass); closure.setDelegate(definer); closure.setResolveStrategy(Closure.DELEGATE_FIRST); closure.call((Object)null); }
public ExpandoMetaClass define(Closure closure) { final DefiningClosure definer = new DefiningClosure(); Object delegate = closure.getDelegate(); closure.setDelegate(definer); closure.setResolveStrategy(Closure.DELEGATE_ONLY); closure.call((Object)null); closure.setDelegate(delegate); closure.setResolveStrategy(Closure.DELEGATE_FIRST); definer.definition = false; return this; }
private String execute(final PreciseShardingValue shardingValue) { Closure<?> result = closure.rehydrate(new Expando(), null, null); result.setResolveStrategy(Closure.DELEGATE_ONLY); result.setProperty(shardingValue.getColumnName(), shardingValue.getValue()); return result.call().toString(); }
private Object evaluateCondition(Closure condition) { condition.setDelegate(new PreconditionContext()); condition.setResolveStrategy(Closure.DELEGATE_ONLY); try { return condition.call(); } catch (Exception e) { throw new ExtensionException("Failed to evaluate @Requires condition", e); } } }
private Object evaluateCondition(Closure condition) { condition.setDelegate(new PreconditionContext()); condition.setResolveStrategy(Closure.DELEGATE_ONLY); try { return condition.call(); } catch (Exception e) { throw new ExtensionException("Failed to evaluate @IgnoreIf condition", e); } } }
public static void curryDelegateAndGetContent(Writer w, Closure c, Object o, boolean first) { StreamingJsonDelegate delegate = new StreamingJsonDelegate(w, first); Closure curried = c.curry(o); curried.setDelegate(delegate); curried.setResolveStrategy(Closure.DELEGATE_FIRST); curried.call(); } }
public static void cloneDelegateAndGetContent(Writer w, Closure c, boolean first) { StreamingJsonDelegate delegate = new StreamingJsonDelegate(w, first); Closure cloned = (Closure) c.clone(); cloned.setDelegate(delegate); cloned.setResolveStrategy(Closure.DELEGATE_FIRST); cloned.call(); }
private boolean satisfiesCondition(IMethodInvocation invocation, Throwable failure) { if (condition == null) { return true; } condition.setDelegate(new RetryConditionContext(invocation, failure)); condition.setResolveStrategy(Closure.DELEGATE_ONLY); try { return GroovyRuntimeUtil.isTruthy(condition.call()); } catch (Exception e) { throw new ExtensionException("Failed to evaluate @Retry condition", e); } }
/** * Create a {@link RequestConfigDelegate} from the given arguments, execute the * config closure, then pass the delegate to {@link #doRequest(RequestConfigDelegate)}, * which actually executes the request. */ protected Object doRequest(URI uri, String method, Object contentType, boolean hasBody, Closure configClosure) throws IOException { HttpRequestBase reqMethod = HttpRequestFactory.createHttpRequest(uri, method, hasBody); RequestConfigDelegate delegate = new RequestConfigDelegate(reqMethod, contentType, this.defaultRequestHeaders, this.defaultResponseHandlers); configClosure.setDelegate(delegate); configClosure.setResolveStrategy(Closure.DELEGATE_FIRST); configClosure.call(reqMethod); return this.doRequest(delegate); }
/** * Factory method for creating <code>JsonDelegate</code>s from closures. * * @param c closure representing JSON objects * @return an instance of <code>JsonDelegate</code> */ public static Map<String, Object> cloneDelegateAndGetContent(Closure<?> c) { JsonDelegate delegate = new JsonDelegate(); Closure<?> cloned = (Closure<?>) c.clone(); cloned.setDelegate(delegate); cloned.setResolveStrategy(Closure.DELEGATE_FIRST); cloned.call(); return delegate.getContent(); }
/** * 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(); }
private Object invokeClosure(IMockInvocation invocation) { Class<?>[] paramTypes = code.getParameterTypes(); if (paramTypes.length == 1 && paramTypes[0] == IMockInvocation.class) { return GroovyRuntimeUtil.invokeClosure(code, invocation); } code.setDelegate(invocation); code.setResolveStrategy(Closure.DELEGATE_FIRST); return GroovyRuntimeUtil.invokeClosure(code, invocation.getArguments()); } }
Closure callable = (Closure) args[args.length - 1]; callable.setDelegate(this); callable.setResolveStrategy(Closure.DELEGATE_FIRST); callable.call(this.currentBeanDefinition);