/** * Returns a callable object for the given method name on the object. * The object acts like a Closure in that it can be called, like a closure * and passed around - though really its a method pointer, not a closure per se. * * @param object the object containing the method * @param methodName the method of interest * @return the resulting closure-like method pointer */ public static Closure getMethodPointer(Object object, String methodName) { return new MethodClosure(object, methodName); }
} else if (value instanceof MethodClosure) { MethodClosure method = (MethodClosure) value; IteratorClosureAdapter adapter = new IteratorClosureAdapter(method.getDelegate()); method.call(adapter); return adapter.asList(); } else if (value instanceof String || value instanceof GString) {
private Object invokeMethodClosure(MethodClosure object, Object[] arguments, Object owner) { String methodName; final MethodClosure mc = object; methodName = mc.getMethod(); final Class ownerClass = owner instanceof Class ? (Class) owner : owner.getClass(); final MetaClass ownerMetaClass = registry.getMetaClass(ownerClass); return ownerMetaClass.invokeMethod(ownerClass, owner, methodName, arguments, false, false); }
@Override public Object get(final Object property) { if (property instanceof String || property instanceof GString) { String key = property.toString(); if ("include".equals(key)) { return new MethodClosure(GroovyTemplateEngine.this, "doInclude").curry(this); } try { return extractors.extractAndTransform(db, key, model, new TemplateEngineAdapter.NoopAdapter()); } catch (NoModelExtractorException e) { // fallback to parent model } } return super.get(property); } };
/** * @deprecated since 0.11.0; explicit groovy utilities/support will be deleted. */ @Deprecated public MethodEffector(MethodClosure mc) { this(new AnnotationsOnMethod((Class<?>)mc.getDelegate(), mc.getMethod()), null); }
Object response = function.call(widgets.stream().map(ValueWidget::getValue).toArray()); if (response instanceof Widget) { ((Widget) response).display();
protected Object doCall(Object arguments) { return InvokerHelper.invokeMethod(getOwner(), method, arguments); }
protected Object doCall(Object arguments) { return InvokerHelper.invokeMethod(getDelegate(), method, arguments); }
@Override public Object get(final Object property) { if (property instanceof String || property instanceof GString) { String key = property.toString(); if ("include".equals(key)) { return new MethodClosure(GroovyTemplateEngine.this, "doInclude").curry(this); } try { return extractors.extractAndTransform(db, key, model, new TemplateEngineAdapter.NoopAdapter()); } catch (NoModelExtractorException e) { // fallback to parent model } } return super.get(property); } };
public MethodEffector(MethodClosure mc) { this(new AnnotationsOnMethod((Class)mc.getDelegate(), mc.getMethod()), null); }
protected Object doCall(Object arguments) { return InvokerHelper.invokeMethod(getOwner(), method, arguments); }
/** * Returns the method pointer for the given object name */ public static Closure getMethodPointer(Object object, String methodName) { if (object == null) { throw new NullPointerException("Cannot access method pointer for '" + methodName + "' on null object"); } return new MethodClosure(object, methodName); }
IteratorClosureAdapter adapter = new IteratorClosureAdapter(method.getDelegate()); method.call(adapter); return adapter.asList();
public Object getProperty(String property) { if ("method".equals(property)) { return getMethod(); } else return super.getProperty(property); } }
protected Object doCall(Object arguments) { return InvokerHelper.invokeMethod(getOwner(), method, arguments); }
/** * Creates default response handlers for {@link Status#SUCCESS success} and * {@link Status#FAILURE failure} status codes. This is used to populate * the handler map when a new HTTPBuilder instance is created. * * @return the default response handler map. * @see #defaultSuccessHandler(HttpResponseDecorator, Object) * @see #defaultFailureHandler(HttpResponseDecorator) */ protected Map<Object, Closure> buildDefaultResponseHandlers() { Map<Object, Closure> map = new StringHashMap<Closure>(); map.put(Status.SUCCESS, new MethodClosure(this, "defaultSuccessHandler")); map.put(Status.FAILURE, new MethodClosure(this, "defaultFailureHandler")); return map; }
IteratorClosureAdapter adapter = new IteratorClosureAdapter(method.getDelegate()); method.call(adapter); return adapter.asList();
public static List<MetaMethod> createMethodList(final String name, final Class declaringClass, final Closure closure) { List<MetaMethod> res = new ArrayList<MetaMethod>(); if (closure instanceof MethodClosure) { MethodClosure methodClosure = (MethodClosure) closure; Object owner = closure.getOwner(); Class ownerClass = (Class) (owner instanceof Class ? owner : owner.getClass()); for (CachedMethod method : ReflectionCache.getCachedClass(ownerClass).getMethods() ) { if (method.getName().equals(methodClosure.getMethod())) { MetaMethod metaMethod = new MethodClosureMetaMethod(name, declaringClass, closure, method); res.add(adjustParamTypesForStdMethods(metaMethod, name)); } } } else { if (closure instanceof GeneratedClosure) { for (CachedMethod method : ReflectionCache.getCachedClass(closure.getClass()).getMethods() ) { if (method.getName().equals("doCall")) { MetaMethod metaMethod = new ClosureMetaMethod(name, declaringClass, closure, method); res.add(adjustParamTypesForStdMethods(metaMethod, name)); } } } else { MetaMethod metaMethod = new AnonymousMetaMethod(closure, name, declaringClass); res.add(adjustParamTypesForStdMethods(metaMethod, name)); } } return res; }
protected Object doCall(Object arguments) { return InvokerHelper.invokeMethod(getOwner(), method, arguments); }
public MethodClosure createMethodClosure() { return new MethodClosure(this, "someMethod"); }