use of com.googlecode.aviator.exception.FunctionNotFoundException in project aviatorscript by killme2008.
the class SeqEveryFunction method call.
@Override
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1, final AviatorObject arg2) {
Object first = arg1.getValue(env);
AviatorFunction fun = FunctionUtils.getFunction(arg2, env, 1);
if (fun == null) {
throw new FunctionNotFoundException("There is no function named " + ((AviatorJavaType) arg2).getName());
}
if (first == null) {
return AviatorBoolean.TRUE;
}
for (Object obj : RuntimeUtils.seq(first, env)) {
if (!fun.call(env, AviatorRuntimeJavaType.valueOf(obj)).booleanValue(env)) {
return AviatorBoolean.FALSE;
}
}
return AviatorBoolean.TRUE;
}
use of com.googlecode.aviator.exception.FunctionNotFoundException in project aviatorscript by killme2008.
the class SeqFilterFunction method call.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1, final AviatorObject arg2) {
Object first = arg1.getValue(env);
AviatorFunction fun = FunctionUtils.getFunction(arg2, env, 1);
if (fun == null) {
throw new FunctionNotFoundException("There is no function named " + ((AviatorJavaType) arg2).getName());
}
if (first == null) {
return AviatorNil.NIL;
}
Sequence seq = RuntimeUtils.seq(first, env);
Collector collector = seq.newCollector(0);
for (Object obj : seq) {
if (fun.call(env, AviatorRuntimeJavaType.valueOf(obj)).booleanValue(env)) {
collector.add(obj);
}
}
return AviatorRuntimeJavaType.valueOf(collector.getRawContainer());
}
use of com.googlecode.aviator.exception.FunctionNotFoundException in project aviatorscript by killme2008.
the class JavaMethodReflectionFunctionMissing method onFunctionMissing.
@Override
public AviatorObject onFunctionMissing(final String name, final Map<String, Object> env, final AviatorObject... args) {
if (args == null || args.length < 1) {
throw new FunctionNotFoundException("Function not found: " + name + ", could not resolve with no arguments");
}
Object firstArg = args[0].getValue(env);
if (firstArg == null) {
throw new FunctionNotFoundException("Function not found: " + name + ", the first argument is null");
}
Class<?> clazz = firstArg.getClass();
Object[] jArgs = new Object[args.length - 1];
for (int i = 1; i < args.length; i++) {
jArgs[i - 1] = args[i].getValue(env);
}
return FunctionUtils.wrapReturn(Reflector.invokeInstanceMethod(clazz, name, firstArg, Reflector.getInstanceMethods(clazz, name), jArgs));
}
use of com.googlecode.aviator.exception.FunctionNotFoundException in project aviatorscript by killme2008.
the class SeqNotAnyFunction method call.
@Override
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1, final AviatorObject arg2) {
Object first = arg1.getValue(env);
AviatorFunction fun = FunctionUtils.getFunction(arg2, env, 1);
if (fun == null) {
throw new FunctionNotFoundException("There is no function named " + ((AviatorJavaType) arg2).getName());
}
if (first == null) {
return AviatorBoolean.TRUE;
}
for (Object obj : RuntimeUtils.seq(first, env)) {
if (fun.call(env, AviatorRuntimeJavaType.valueOf(obj)).booleanValue(env)) {
return AviatorBoolean.FALSE;
}
}
return AviatorBoolean.TRUE;
}
use of com.googlecode.aviator.exception.FunctionNotFoundException in project aviatorscript by killme2008.
the class SeqReduceFunction method call.
@Override
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1, final AviatorObject arg2, final AviatorObject arg3) {
Object first = arg1.getValue(env);
AviatorFunction fun = FunctionUtils.getFunction(arg2, env, 2);
if (fun == null) {
throw new FunctionNotFoundException("There is no function named " + ((AviatorJavaType) arg2).getName());
}
if (first == null) {
return arg3;
}
AviatorObject result = arg3;
for (Object obj : RuntimeUtils.seq(first, env)) {
result = fun.call(env, result, AviatorRuntimeJavaType.valueOf(obj));
}
return result;
}
Aggregations