/** * Binds an object to this closure. * @param closed The object that has to be bound to this closure * @param closedClass The actual class of the proxied object * @return An instance of the closedClass that is actually a proxy used to register all the invocation on the closed object */ public <T> T of(Object closed, Class<T> closedClass) { setClosed(closed); return createProxyClosure(this, closedClass); }
public Object invoke(Object proxy, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException { if (registered) return method.invoke(proxy, args); registered = true; closure.bindInvocation(method, args); DelayedClosure.call(); Class<?> returnType = method.getReturnType(); if (returnType == Void.TYPE) { closure.closeUnhandledInvocations(); return null; } return createProxyClosure(closure, returnType); } }