if(params.isEmpty()) {
return body;
} else {
// Note that create function always generates new body expression for each call,
// and must care about parameters reference.
UserFunction newuf = ObjectUtils.deepCopy(func);
List<ParametricVariable> newParams = newuf.getParameters();
final int psize = newParams.size();
for(int i = 0; i < psize; i++) {
ParametricVariable p = newParams.get(i);
Type implicitParamType = p.getType();
XQExpression arg = argv.get(i);
Type argType = arg.getType();
if(implicitParamType != Untyped.UNTYPED && !implicitParamType.accepts(argType)) {
// type promotion is required for arguments
p.setValue(new TypePromotedExpr(arg, implicitParamType));
} else {
p.setValue(arg);
}
}
XQExpression newbody = newuf.getBodyExpression();
statEnv.setFunctionManager(funcMgr);
if(LOG.isDebugEnabled()) {
LOG.debug("Inlined the function '" + QNameUtil.toLexicalForm(newuf.getName()) + "'");
}
return newbody;
}
}