@SuppressWarnings("unused") @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value="UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS",justification="Closure invokes this via reflection") public Object doCall(Object[] args) throws ChannelClosedException { if (args.length == 1 && args[0] instanceof ChannelClosedException) { throw (ChannelClosedException)args[0]; } return originalErrorHook.call(args); } });
@Override public Object call() { cl.call(); return ""; }
/** * Intercepts output - moret common case of byte[] */ public void write(byte[] b, int off, int len) throws IOException { Boolean result = (Boolean) callback.call(new String(b, off, len)); if (result) { out.write(b, off, len); } }
public String stringOf(Closure cl) throws IOException { Writer old = out; StringWriter stringWriter = new StringWriter(32); out = stringWriter; Object result = cl.call(); if (result!=null && result!=this) { stringWriter.append(result.toString()); } out = old; return stringWriter.toString(); }
/** * When a method argument is only a closure it is a set of bean definitions. * @param callable the closure argument * @return this {@code GroovyBeanDefinitionReader} instance */ protected GroovyBeanDefinitionReader invokeBeanDefiningClosure(Closure callable) { callable.setDelegate(this); callable.call(); finalizeDeferredProperties(); return this; }
/** * Call the closure once for each row in the result set. * * @param closure the closure to perform on each row * @throws SQLException if something goes wrong */ public void eachRow(Closure closure) throws SQLException { while (next()) { closure.call(this); } } // Implementation of java.sql.getResultSet()
public void setProperty(String property, Object newValue) { if ("trigger".equals(property)) { this.out = newValue; this.root.call(this); } else { super.setProperty(property, newValue); } } }
/** * When an methods argument is only a closure it is a set of bean definitions * * @param callable The closure argument */ public BeanBuilder beans(Closure callable) { callable.setDelegate(this); // callable.setResolveStrategy(Closure.DELEGATE_FIRST); callable.call(); finalizeDeferredProperties(); return this; }
private Object callGlobal(String name, Object[] args, ScriptContext ctx) { Closure<?> closure = globalClosures.get(name); if (closure != null) { return closure.call(args); } else { // Look for closure valued variable in the // given ScriptContext. If available, call it. Object value = ctx.getAttribute(name); if (value instanceof Closure) { return ((Closure) value).call(args); } // else fall thru.. } throw new MissingMethodException(name, getClass(), args); }
/** * When a method argument is only a closure it is a set of bean definitions. * @param callable the closure argument * @return this {@code GroovyBeanDefinitionReader} instance */ protected GroovyBeanDefinitionReader invokeBeanDefiningClosure(Closure callable) { callable.setDelegate(this); callable.call(); finalizeDeferredProperties(); return this; }
/** * Note: This method may throw checked exceptions although it doesn't say so. */ @SuppressWarnings("unchecked") public static <T> T invokeClosure(Closure<T> closure, Object... args) { try { return closure.call(args); } catch (InvokerInvocationException e) { ExceptionUtil.sneakyThrow(e.getCause()); return null; // never reached } }
callable.call(this.currentBeanDefinition);
public GPathResult find(final Closure closure) { final Iterator iter = iterator(); while (iter.hasNext()) { final Object node = iter.next(); if (DefaultTypeTransformation.castToBoolean(closure.call(new Object[]{node}))) { return (GPathResult) node; } } return new NoChildren(this, this.name, namespaceTagHints); }
public GPathResult find(final Closure closure) { if (DefaultTypeTransformation.castToBoolean(closure.call(new Object[]{this}))) { return this; } else { return new NoChildren(this, "", this.namespaceTagHints); } }
protected void applyPropertyToBeanDefinition(String name, Object value) { if (value instanceof GString) { value = value.toString(); } if (addDeferredProperty(name, value)) { return; } else if (value instanceof Closure) { GroovyBeanDefinitionWrapper current = this.currentBeanDefinition; try { Closure callable = (Closure) value; Class<?> parameterType = callable.getParameterTypes()[0]; if (Object.class == parameterType) { this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(""); callable.call(this.currentBeanDefinition); } else { this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(null, parameterType); callable.call((Object) null); } value = this.currentBeanDefinition.getBeanDefinition(); } finally { this.currentBeanDefinition = current; } } this.currentBeanDefinition.addProperty(name, value); }
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); } } }
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); }