use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method getScriptFunctionArguments.
@Override
public ArrayList<Argument> getScriptFunctionArguments(ExprData data) throws TemplateException {
// arguments
LitBoolean passByRef;
Expression displayName;
Expression hint;
Map<String, Attribute> meta;
String _name;
ArrayList<Argument> result = new ArrayList<Argument>();
do {
comments(data);
// finish
if (data.srcCode.isCurrent(')'))
break;
// attribute
// name
// String idName=identifier(data,false,true);
boolean required = false;
String idName = variableDec(data, false);
// required
if ("required".equalsIgnoreCase(idName)) {
comments(data);
String idName2 = variableDec(data, false);
if (idName2 != null) {
idName = idName2;
required = true;
}
if (idName == null)
throw new TemplateException(data.srcCode, "invalid argument definition");
}
String typeName = "any";
if (idName == null)
throw new TemplateException(data.srcCode, "invalid argument definition");
comments(data);
if (!data.srcCode.isCurrent(')') && !data.srcCode.isCurrent('=') && !data.srcCode.isCurrent(':') && !data.srcCode.isCurrent(',')) {
typeName = idName.toLowerCase();
// MUST was upper case before, is this a problem?
idName = identifier(data, false);
} else if (idName.indexOf('.') != -1 || idName.indexOf('[') != -1) {
throw new TemplateException(data.srcCode, "invalid argument name [" + idName + "] definition");
}
if (idName == null)
throw new TemplateException(data.srcCode, "invalid argument definition");
comments(data);
Expression defaultValue;
if (data.srcCode.isCurrent('=') || data.srcCode.isCurrent(':')) {
data.srcCode.next();
comments(data);
defaultValue = expression(data);
} else
defaultValue = null;
// assign meta data defined in doc comment
passByRef = data.factory.TRUE();
displayName = data.factory.EMPTY();
hint = data.factory.EMPTY();
meta = null;
if (data.docComment != null) {
Map<String, Attribute> params = data.docComment.getParams();
Attribute[] attrs = params.values().toArray(new Attribute[params.size()]);
Attribute attr;
String name;
for (int i = 0; i < attrs.length; i++) {
attr = attrs[i];
name = attr.getName();
// hint
if (idName.equalsIgnoreCase(name) || name.equalsIgnoreCase(idName + ".hint")) {
hint = data.factory.toExprString(attr.getValue());
params.remove(name);
}
// meta
if (StringUtil.startsWithIgnoreCase(name, idName + ".")) {
if (name.length() > idName.length() + 1) {
if (meta == null)
meta = new HashMap<String, Attribute>();
_name = name.substring(idName.length() + 1);
meta.put(_name, new Attribute(attr.isDynamicType(), _name, attr.getValue(), attr.getType()));
}
params.remove(name);
}
}
}
// argument attributes
Attribute[] _attrs = attributes(null, null, data, COMMA_ENDBRACKED, data.factory.EMPTY(), Boolean.TRUE, null, false, NO_ATTR_SEP, true);
Attribute _attr;
if (!ArrayUtil.isEmpty(_attrs)) {
if (meta == null)
meta = new HashMap<String, Attribute>();
for (int i = 0; i < _attrs.length; i++) {
_attr = _attrs[i];
meta.put(_attr.getName(), _attr);
}
}
result.add(new Argument(data.factory.createLitString(idName), data.factory.createLitString(typeName), data.factory.createLitBoolean(required), defaultValue, passByRef, displayName, hint, meta));
comments(data);
} while (data.srcCode.forwardIfCurrent(','));
return result;
}
use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method attribute.
private final Attribute attribute(TagLibTag tlt, ExprData data, ArrayList<String> args, Expression defaultValue, Object oAllowExpression, boolean allowTwiceAttr, boolean allowColonSeparator) throws TemplateException {
StringBuffer sbType = new StringBuffer();
RefBoolean dynamic = new RefBooleanImpl(false);
// Name
String name = attributeName(data.srcCode, args, tlt, dynamic, sbType, allowTwiceAttr, !allowColonSeparator);
String nameLC = name == null ? null : name.toLowerCase();
boolean allowExpression = false;
if (oAllowExpression instanceof Boolean)
allowExpression = ((Boolean) oAllowExpression).booleanValue();
else if (oAllowExpression instanceof String)
allowExpression = ((String) oAllowExpression).equalsIgnoreCase(nameLC);
Expression value = null;
comments(data);
// value
boolean hasValue = data.srcCode.forwardIfCurrent('=') || (allowColonSeparator && data.srcCode.forwardIfCurrent(':'));
if (hasValue) {
comments(data);
value = attributeValue(data, allowExpression);
} else {
value = defaultValue;
}
comments(data);
// Type
TagLibTagAttr tlta = null;
if (tlt != null) {
tlta = tlt.getAttribute(nameLC, true);
if (tlta != null && tlta.getName() != null)
nameLC = tlta.getName();
}
return new Attribute(dynamic.toBooleanValue(), name, tlta != null ? CastOther.toExpression(value, tlta.getType()) : value, sbType.toString(), !hasValue);
}
use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class CFMLScriptTransformer method expression.
@Override
public final Expression expression(ExprData data) throws TemplateException {
Expression expr;
expr = super.expression(data);
comments(data);
return expr;
}
use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class TagFunction method createFunction.
private Function createFunction(Page page, Body body, RefBoolean isStatic, boolean defaultOutput) throws TransformerException {
Attribute attr;
LitString ANY = page.getFactory().createLitString("any");
LitString PUBLIC = page.getFactory().createLitString("public");
// name
Expression name = removeAttribute("name").getValue();
/*if(name instanceof LitString) {
((LitString)name).upperCase();
}*/
// return
attr = removeAttribute("returntype");
// if(attr==null) attr = getAttribute("return");
// if(attr==null) attr = getAttribute("type");
Expression returnType = (attr == null) ? ANY : attr.getValue();
// output
attr = removeAttribute("output");
Expression output = (attr == null) ? (defaultOutput ? page.getFactory().TRUE() : page.getFactory().TRUE()) : attr.getValue();
// bufferOutput
attr = removeAttribute("bufferoutput");
Expression bufferOutput = (attr == null) ? null : attr.getValue();
// modifier
isStatic.setValue(false);
int modifier = Component.MODIFIER_NONE;
attr = removeAttribute("modifier");
if (attr != null) {
Expression val = attr.getValue();
if (val instanceof Literal) {
Literal l = (Literal) val;
String str = StringUtil.emptyIfNull(l.getString()).trim();
if ("abstract".equalsIgnoreCase(str))
modifier = Component.MODIFIER_ABSTRACT;
else if ("final".equalsIgnoreCase(str))
modifier = Component.MODIFIER_FINAL;
else if ("static".equalsIgnoreCase(str))
isStatic.setValue(true);
}
}
// access
attr = removeAttribute("access");
Expression access = (attr == null) ? PUBLIC : attr.getValue();
// dspLabel
attr = removeAttribute("displayname");
Expression displayname = (attr == null) ? page.getFactory().EMPTY() : attr.getValue();
// hint
attr = removeAttribute("hint");
Expression hint = (attr == null) ? page.getFactory().EMPTY() : attr.getValue();
// description
attr = removeAttribute("description");
Expression description = (attr == null) ? page.getFactory().EMPTY() : attr.getValue();
// returnformat
attr = removeAttribute("returnformat");
Expression returnFormat = (attr == null) ? null : attr.getValue();
// secureJson
attr = removeAttribute("securejson");
Expression secureJson = (attr == null) ? null : attr.getValue();
// verifyClient
attr = removeAttribute("verifyclient");
Expression verifyClient = (attr == null) ? null : attr.getValue();
// localMode
attr = removeAttribute("localmode");
Expression localMode = (attr == null) ? null : attr.getValue();
// cachedWithin
Literal cachedWithin = null;
attr = removeAttribute("cachedwithin");
if (attr != null) {
Expression val = attr.getValue();
if (val instanceof Literal)
cachedWithin = ((Literal) val);
}
String strAccess = ((LitString) access).getString();
int acc = ComponentUtil.toIntAccess(strAccess, -1);
if (acc == -1)
throw new TransformerException("invalid access type [" + strAccess + "], access types are remote, public, package, private", getStart());
Function func = new FunctionImpl(page, name, returnType, returnFormat, output, bufferOutput, acc, displayname, description, hint, secureJson, verifyClient, localMode, cachedWithin, modifier, body, getStart(), getEnd());
// %**%
Map attrs = getAttributes();
Iterator it = attrs.entrySet().iterator();
HashMap<String, Attribute> metadatas = new HashMap<String, Attribute>();
while (it.hasNext()) {
attr = (Attribute) ((Map.Entry) it.next()).getValue();
metadatas.put(attr.getName(), attr);
}
func.setMetaData(metadatas);
return func;
}
use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class TagFunction method addArgument.
private void addArgument(Function func, Tag tag) {
Attribute attr;
// name
Expression name = tag.removeAttribute("name").getValue();
// type
attr = tag.removeAttribute("type");
Expression type = (attr == null) ? tag.getFactory().createLitString("any") : attr.getValue();
// required
attr = tag.removeAttribute("required");
Expression required = (attr == null) ? tag.getFactory().FALSE() : attr.getValue();
// default
attr = tag.removeAttribute("default");
Expression defaultValue = (attr == null) ? null : attr.getValue();
// passby
attr = tag.removeAttribute("passby");
LitBoolean passByReference = tag.getFactory().TRUE();
if (attr != null) {
// i can cast irt to LitString because he evulator check this before
String str = ((LitString) attr.getValue()).getString();
if (str.trim().equalsIgnoreCase("value"))
passByReference = tag.getFactory().FALSE();
}
// displayname
attr = tag.removeAttribute("displayname");
Expression displayName = (attr == null) ? tag.getFactory().EMPTY() : attr.getValue();
// hint
attr = tag.removeAttribute("hint");
if (attr == null)
attr = tag.removeAttribute("description");
Expression hint;
if (attr == null)
hint = tag.getFactory().EMPTY();
else
hint = attr.getValue();
func.addArgument(name, type, required, defaultValue, passByReference, displayName, hint, tag.getAttributes());
}
Aggregations