use of lucee.transformer.library.function.FunctionLibFunctionArg in project Lucee by lucee.
the class BIF method call.
@Override
public Object call(PageContext pageContext, Object[] args, boolean doIncludePath) throws PageException {
ArrayList<FunctionLibFunctionArg> flfas = flf.getArg();
FunctionLibFunctionArg flfa;
List<Ref> refs = new ArrayList<Ref>();
for (int i = 0; i < args.length; i++) {
if (i >= flfas.size())
throw new ApplicationException("too many Attributes in function call [" + flf.getName() + "]");
flfa = flfas.get(i);
refs.add(new Casting(flfa.getTypeAsString(), flfa.getType(), args[i]));
}
BIFCall call = new BIFCall(flf, refs.toArray(new Ref[refs.size()]));
return call.getValue(pageContext);
}
use of lucee.transformer.library.function.FunctionLibFunctionArg in project Lucee by lucee.
the class FunctionException method getFunctionInfo.
private static String getFunctionInfo(PageContext pc, String functionName) {
FunctionLib[] flds;
int dialect = pc.getCurrentTemplateDialect();
flds = ((ConfigImpl) pc.getConfig()).getFLDs(dialect);
FunctionLibFunction function = null;
for (int i = 0; i < flds.length; i++) {
function = flds[i].getFunction(functionName.toLowerCase());
if (function != null)
break;
}
if (function == null)
return "";
StringBuilder rtn = new StringBuilder();
rtn.append(function.getName() + "(");
int optionals = 0;
ArrayList<FunctionLibFunctionArg> args = function.getArg();
for (int i = 0; i < args.size(); i++) {
FunctionLibFunctionArg arg = args.get(i);
if (i != 0)
rtn.append(", ");
if (!arg.getRequired()) {
rtn.append("[");
optionals++;
}
rtn.append(arg.getName());
rtn.append(":");
rtn.append(arg.getTypeAsString());
}
for (int i = 0; i < optionals; i++) rtn.append("]");
rtn.append("):" + function.getReturnTypeAsString());
return rtn.toString();
}
use of lucee.transformer.library.function.FunctionLibFunctionArg in project Lucee by lucee.
the class AbstrCFMLExprTransformer method getFunctionMemberAttrs.
private int getFunctionMemberAttrs(ExprData data, ExprString name, boolean checkLibrary, Func fm, FunctionLibFunction flf) throws TemplateException {
// Function Attributes
ArrayList<FunctionLibFunctionArg> arrFuncLibAtt = null;
// int libLen = 0;
if (checkLibrary) {
arrFuncLibAtt = flf.getArg();
// libLen = arrFuncLibAtt.size();
}
int count = 0;
do {
data.srcCode.next();
comments(data);
// finish
if (count == 0 && data.srcCode.isCurrent(')'))
break;
// Argument arg;
if (checkLibrary && flf.getArgType() != FunctionLibFunction.ARG_DYNAMIC) {
// current attribues from library
String _type;
try {
_type = arrFuncLibAtt.get(count).getTypeAsString();
} catch (IndexOutOfBoundsException e) {
_type = null;
}
fm.addArgument(functionArgument(data, _type, false));
} else {
fm.addArgument(functionArgument(data, false));
}
comments(data);
count++;
if (data.srcCode.isCurrent(')'))
break;
} while (data.srcCode.isCurrent(','));
if (!data.srcCode.forwardIfCurrent(')')) {
if (name != null) {
throw new TemplateException(data.srcCode, "Invalid Syntax Closing [)] for function [" + (flf != null ? flf.getName() : ASMUtil.display(name)) + "] not found");
}
throw new TemplateException(data.srcCode, "Invalid Syntax Closing [)] not found");
}
return count;
}
use of lucee.transformer.library.function.FunctionLibFunctionArg in project Lucee by lucee.
the class VT method getValue.
@Override
public Object getValue(PageContext pc) throws PageException {
Object[] arguments = null;
if (isDynamic()) {
arguments = RefUtil.getValue(pc, refArgs);
if (flf.hasDefaultValues()) {
List<Object> tmp = new ArrayList<Object>();
ArrayList<FunctionLibFunctionArg> args = flf.getArg();
Iterator<FunctionLibFunctionArg> it = args.iterator();
FunctionLibFunctionArg arg;
while (it.hasNext()) {
arg = it.next();
if (arg.getDefaultValue() != null)
tmp.add(new FunctionValueImpl(arg.getName(), arg.getDefaultValue()));
}
for (int i = 0; i < arguments.length; i++) {
tmp.add(arguments[i]);
}
arguments = tmp.toArray();
}
arguments = new Object[] { arguments };
} else {
if (isNamed(pc, refArgs)) {
FunctionValue[] fvalues = getFunctionValues(pc, refArgs);
String[] names = getNames(fvalues);
ArrayList<FunctionLibFunctionArg> list = flf.getArg();
Iterator<FunctionLibFunctionArg> it = list.iterator();
arguments = new Object[list.size()];
FunctionLibFunctionArg flfa;
int index = 0;
VT vt;
while (it.hasNext()) {
flfa = it.next();
vt = getMatchingValueAndType(flfa, fvalues, names);
if (vt.index != -1)
names[vt.index] = null;
arguments[index++] = new Casting(vt.type, CFTypes.toShort(vt.type, false, CFTypes.TYPE_UNKNOW), vt.value).getValue(pc);
}
for (int y = 0; y < names.length; y++) {
if (names[y] != null) {
ExpressionException ee = new InterpreterException("argument [" + names[y] + "] is not allowed for function [" + flf.getName() + "]");
UDFUtil.addFunctionDoc(ee, flf);
throw ee;
}
}
} else {
arguments = RefUtil.getValue(pc, refArgs);
}
}
BIF bif = flf.getBIF();
if (flf.getMemberChaining() && obj != null) {
bif.invoke(pc, arguments);
return obj;
}
if (!isDynamic() && flf.getArgMin() > arguments.length) {
throw new FunctionException(pc, flf.getName(), flf.getArgMin(), flf.getArgMax(), arguments.length);
}
return Caster.castTo(pc, flf.getReturnTypeAsString(), bif.invoke(pc, arguments), false);
}
use of lucee.transformer.library.function.FunctionLibFunctionArg in project Lucee by lucee.
the class GetFunctionData method javaBasedFunction.
private static Struct javaBasedFunction(FunctionLibFunction function) throws PageException {
Struct sct = new StructImpl();
sct.set(KeyConstants._name, function.getName());
sct.set(KeyConstants._status, TagLibFactory.toStatus(function.getStatus()));
if (function.getIntroduced() != null)
sct.set(INTRODUCED, function.getIntroduced().toString());
// else if(inside.equals("introduced")) att.setIntroduced(value);
sct.set(KeyConstants._description, StringUtil.emptyIfNull(function.getDescription()));
if (!ArrayUtil.isEmpty(function.getKeywords()))
sct.set("keywords", Caster.toArray(function.getKeywords()));
sct.set(RETURN_TYPE, StringUtil.emptyIfNull(function.getReturnTypeAsString()));
sct.set(ARGUMENT_TYPE, StringUtil.emptyIfNull(function.getArgTypeAsString()));
sct.set(ARG_MIN, Caster.toDouble(function.getArgMin()));
sct.set(ARG_MAX, Caster.toDouble(function.getArgMax()));
sct.set(KeyConstants._type, "java");
String[] names = function.getMemberNames();
if (!ArrayUtil.isEmpty(names) && function.getMemberType() != CFTypes.TYPE_UNKNOW) {
StructImpl mem = new StructImpl();
sct.set(KeyConstants._member, mem);
mem.set(KeyConstants._name, names[0]);
mem.set(KeyConstants._chaining, Caster.toBoolean(function.getMemberChaining()));
mem.set(KeyConstants._type, function.getMemberTypeAsString());
mem.set("position", Caster.toDouble(function.getMemberPosition()));
}
Array _args = new ArrayImpl();
sct.set(KeyConstants._arguments, _args);
if (function.getArgType() != FunctionLibFunction.ARG_DYNAMIC) {
ArrayList<FunctionLibFunctionArg> args = function.getArg();
for (int i = 0; i < args.size(); i++) {
FunctionLibFunctionArg arg = args.get(i);
Struct _arg = new StructImpl();
_arg.set(KeyConstants._required, arg.getRequired() ? Boolean.TRUE : Boolean.FALSE);
_arg.set(KeyConstants._type, StringUtil.emptyIfNull(arg.getTypeAsString()));
_arg.set(KeyConstants._name, StringUtil.emptyIfNull(arg.getName()));
_arg.set(KeyConstants._status, TagLibFactory.toStatus(arg.getStatus()));
if (arg.getIntroduced() != null)
_arg.set(INTRODUCED, arg.getIntroduced().toString());
_arg.set("defaultValue", arg.getDefaultValue());
_arg.set(KeyConstants._description, StringUtil.toStringEmptyIfNull(arg.getDescription()));
_args.append(_arg);
}
}
return sct;
}
Aggregations