use of lucee.transformer.expression.literal.LitBoolean in project Lucee by lucee.
the class Component method evaluate.
@Override
public TagLibTag evaluate(TagLibTag tagLibTag, Tag tag) throws AttributeEvaluatorException {
tagLibTag.setParseBody(false);
Attribute attr = tag.getAttribute("output");
if (attr != null) {
Expression expr = attr.getValue();
if (!(expr instanceof LitBoolean))
throw new AttributeEvaluatorException("Attribute output of the Tag Component, must be a static boolean value (true or false)");
if (((LitBoolean) expr).getBooleanValue())
tagLibTag.setParseBody(true);
}
return tagLibTag;
}
use of lucee.transformer.expression.literal.LitBoolean in project Lucee by lucee.
the class Function method evaluate.
@Override
public TagLibTag evaluate(TagLibTag tagLibTag, Tag tag) throws AttributeEvaluatorException {
tagLibTag.setParseBody(false);
Attribute attrOutput = tag.getAttribute("output");
if (attrOutput == null)
return tagLibTag;
Expression expr = CastBoolean.toExprBoolean(attrOutput.getValue());
if (!(expr instanceof LitBoolean))
throw new AttributeEvaluatorException("Attribute output of the Tag Function, must be a literal boolean value (true or false)");
boolean output = ((LitBoolean) expr).getBooleanValue();
if (output)
tagLibTag.setParseBody(true);
return tagLibTag;
}
use of lucee.transformer.expression.literal.LitBoolean in project Lucee by lucee.
the class Function method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag, FunctionLib[] flibs) throws EvaluatorException {
// Body p=(Body) tag.getParent();
// Statement pp = p.getParent();
boolean isCI = true;
try {
isCI = ASMUtil.getAncestorPage(tag).isComponent() || ASMUtil.getAncestorPage(tag).isInterface();
} catch (TransformerException e) {
}
Attribute attrName = tag.getAttribute("name");
if (attrName != null) {
Expression expr = attrName.getValue();
PageSource ps = null;
if (expr instanceof LitString && !isCI) {
Page p = ASMUtil.getAncestorPage(tag, null);
if (p != null) {
SourceCode sc = p.getSourceCode();
if (sc instanceof PageSourceCode) {
PageSourceCode psc = (PageSourceCode) sc;
ps = psc.getPageSource();
}
}
checkFunctionName(((LitString) expr).getString(), flibs, ps);
}
}
// attribute modifier
boolean isStatic = false;
{
Attribute attrModifier = tag.getAttribute("modifier");
if (attrModifier != null) {
ExprString expr = tag.getFactory().toExprString(attrModifier.getValue());
if (!(expr instanceof Literal))
throw new EvaluatorException("Attribute modifier of the Tag Function, must be one of the following literal string values: [abstract,final,static]");
String modifier = StringUtil.emptyIfNull(((Literal) expr).getString()).trim();
if (!StringUtil.isEmpty(modifier) && !"abstract".equalsIgnoreCase(modifier) && !"final".equalsIgnoreCase(modifier) && !"static".equalsIgnoreCase(modifier))
throw new EvaluatorException("Attribute modifier of the Tag Function, must be one of the following literal string values: [abstract,final,static]");
isStatic = "static".equalsIgnoreCase(modifier);
boolean abstr = "abstract".equalsIgnoreCase(modifier);
if (abstr)
throwIfNotEmpty(tag);
}
}
// cachedWithin
{
Attribute attrCachedWithin = tag.getAttribute("cachedwithin");
if (attrCachedWithin != null) {
Expression val = attrCachedWithin.getValue();
tag.addAttribute(new Attribute(attrCachedWithin.isDynamicType(), attrCachedWithin.getName(), ASMUtil.cachedWithinValue(val), attrCachedWithin.getType()));
}
}
// Attribute localMode
{
Attribute attrLocalMode = tag.getAttribute("localmode");
if (attrLocalMode != null) {
Expression expr = attrLocalMode.getValue();
String str = ASMUtil.toString(expr, null);
if (!StringUtil.isEmpty(str) && AppListenerUtil.toLocalMode(str, -1) == -1)
throw new EvaluatorException("Attribute localMode of the Tag Function, must be a literal value (modern, classic, true or false)");
// boolean output = ((LitBoolean)expr).getBooleanValue();
// if(!output) ASMUtil.removeLiterlChildren(tag, true);
}
}
// Attribute Output
{
Attribute attrOutput = tag.getAttribute("output");
if (attrOutput != null) {
Expression expr = tag.getFactory().toExprBoolean(attrOutput.getValue());
if (!(expr instanceof LitBoolean))
throw new EvaluatorException("Attribute output of the Tag Function, must be a literal boolean value (true or false, yes or no)");
}
}
// Buffer output
{
Attribute attrBufferOutput = tag.getAttribute("bufferoutput");
if (attrBufferOutput != null) {
Expression expr = tag.getFactory().toExprBoolean(attrBufferOutput.getValue());
if (!(expr instanceof LitBoolean))
throw new EvaluatorException("Attribute bufferOutput of the Tag Function, must be a literal boolean value (true or false, yes or no)");
}
}
// check attribute values
Map<String, Attribute> attrs = tag.getAttributes();
Iterator<Attribute> it = attrs.values().iterator();
while (it.hasNext()) {
checkAttributeValue(tag, it.next());
}
// add to static scope
if (isStatic) {
// remove that tag from parent
ASMUtil.remove(tag);
Body body = (Body) tag.getParent();
StaticBody sb = Static.getStaticBody(body);
sb.addStatement(tag);
}
}
use of lucee.transformer.expression.literal.LitBoolean 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.literal.LitBoolean 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