@Override
public Object eval(ExpressionContext context, CambridgeExpression[] params) throws ExpressionEvaluationException {
Class<?>[] parameterTypes = method.getParameterTypes();
if (parameterTypes != null && (params == null || parameterTypes.length != params.length)) {
throw new ExpressionEvaluationException("Invalid number of parameters provided for calling static method " + method.toString());
}
try {
if (params == null || params.length == 0) {
return method.invoke(null);
}
Object[] args = new Object[params.length];
for (int i = 0, paramsLength = params.length; i < paramsLength; i++) {
CambridgeExpression e = params[i];
args[i] = e.eval(context);
if (method.isVarArgs() && i == params.length - 1 && parameterTypes != null && !(parameterTypes[i].isAssignableFrom(args[i].getClass()))) {
args[i] = new Object[] {args[i]};
}
}
return method.invoke(null, args);
} catch (Exception e) {
throw new ExpressionEvaluationException("Error calling static method " + method.toString(), e);
}
}