/** * {@inheritDoc} */ public Object invoke(Object obj, Object... args) { try { return method.invoke(obj, args); } catch (Exception e) { throw new WrongClosureInvocationException("Error invoking " + method + " on " + obj, e); } }
private void checkClosedType(Object toBeClosed) { if (!((Class<?>)closed).isInstance(toBeClosed)) throw new WrongClosureInvocationException("The first var must be of class " + closed); }
/** * {@inheritDoc} */ public Object invoke(Object obj, Object... args) { try { return constructor.newInstance(args); } catch (Exception e) { throw new WrongClosureInvocationException("Error invoking constroctor for " + constructor.getDeclaringClass(), e); } }
private boolean checkParams(Object... vars) { if (vars == null || vars.length == 0) { if (freeVarsNumber != 0) throw new WrongClosureInvocationException("Closure invoked without vars instead of the expected " + freeVarsNumber); if (curriedVars == null && argsList == null) return true; } if (freeVarsNumber != vars.length) throw new WrongClosureInvocationException("Closure invoked with " + vars.length + " vars instead of the expected " + freeVarsNumber); if (isClosedOnFreeVar()) checkClosedType(vars[0]); return false; }