use of freemarker.template.TemplateMethodModel in project freemarker by apache.
the class MethodCall method _eval.
@Override
TemplateModel _eval(Environment env) throws TemplateException {
TemplateModel targetModel = target.eval(env);
if (targetModel instanceof TemplateMethodModel) {
TemplateMethodModel targetMethod = (TemplateMethodModel) targetModel;
List argumentStrings = targetMethod instanceof TemplateMethodModelEx ? arguments.getModelList(env) : arguments.getValueList(env);
Object result = targetMethod.exec(argumentStrings);
return env.getObjectWrapper().wrap(result);
} else if (targetModel instanceof Macro) {
Macro func = (Macro) targetModel;
env.setLastReturnValue(null);
if (!func.isFunction()) {
throw new _MiscTemplateException(env, "A macro cannot be called in an expression. (Functions can be.)");
}
Writer prevOut = env.getOut();
try {
env.setOut(NullWriter.INSTANCE);
env.invoke(func, null, arguments.items, null, this);
} catch (IOException e) {
// Should not occur
throw new TemplateException("Unexpected exception during function execution", e, env);
} finally {
env.setOut(prevOut);
}
return env.getLastReturnValue();
} else {
throw new NonMethodException(target, targetModel, env);
}
}
Aggregations