use of lucee.transformer.expression.literal.LitBoolean in project Lucee by lucee.
the class Component method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag tlt) throws EvaluatorException {
/*if(tag instanceof TagOther) {
print.e(((TagOther)tag).getFullname());
}*/
TagCIObject tc = (TagCIObject) tag;
Statement pPage = tag.getParent();
// String className=tag.getTagLibTag().getTagClassName();
Page page;
// move components inside script to root
if (pPage instanceof Page) {
page = (Page) pPage;
} else {
// is in script
Tag p = ASMUtil.getParentTag(tag);
if ((pPage = p.getParent()) instanceof Page && p.getTagLibTag().getName().equalsIgnoreCase(((Page) pPage).getSourceCode().getDialect() == CFMLEngine.DIALECT_CFML ? Constants.CFML_SCRIPT_TAG_NAME : Constants.LUCEE_SCRIPT_TAG_NAME)) {
// chnaged order of the condition, not sure if this is ok
page = (Page) pPage;
// move imports from script to component body
List<Statement> children = p.getBody().getStatements();
Iterator<Statement> it = children.iterator();
Statement stat;
Tag t;
while (it.hasNext()) {
stat = it.next();
if (!(stat instanceof Tag))
continue;
t = (Tag) stat;
if (t.getTagLibTag().getName().equals("import")) {
tag.getBody().addStatement(t);
}
}
// move to page
ASMUtil.move(tag, page);
// if(!inline)ASMUtil.replace(p, tag, false);
} else
throw new EvaluatorException("Wrong Context, tag " + tlt.getFullName() + " can't be inside other tags, tag is inside tag " + p.getFullname());
}
// Page page=(Page) pPage;
Boolean insideCITemplate = isInsideCITemplate(page);
boolean main = isMainComponent(page, tc);
// is a full grown component or a inline component
if (insideCITemplate == Boolean.FALSE) {
throw new EvaluatorException("Wrong Context, " + tlt.getFullName() + " tag must be inside a file with the extension " + Constants.getCFMLComponentExtension() + " or " + Constants.getLuceeComponentExtension());
}
// if(count>1)
// throw new EvaluatorException("inside one cfc file only one tag "+tlt.getFullName()+" is allowed, now we have "+count);
boolean isComponent = tlt.getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Component");
/*boolean isInterface="lucee.runtime.tag.Interface".equals(tlt.getTagClassName());
if(main) {
if(isComponent) page.setIsComponent(true);
else if(isInterface) page.setIsInterface(true);
}*/
tc.setMain(main);
// Attributes
// Name
String name = null;
if (!main) {
Map<String, Attribute> attrs = tag.getAttributes();
if (attrs.size() > 0) {
Attribute first = attrs.values().iterator().next();
if (first.isDefaultValue()) {
name = first.getName();
}
}
if (name == null) {
Attribute attr = tag.getAttribute("name");
if (attr != null) {
Expression expr = tag.getFactory().toExprString(attr.getValue());
if (!(expr instanceof LitString))
throw new EvaluatorException("Name of the component " + tlt.getFullName() + ", must be a literal string value");
name = ((LitString) expr).getString();
} else
throw new EvaluatorException("Missing name of the component " + tlt.getFullName() + "");
}
tc.setName(name);
}
// output
// "output=true" is handled in "lucee.transformer.cfml.attributes.impl.Function"
Attribute attr = tag.getAttribute("output");
if (attr != null) {
Expression expr = tag.getFactory().toExprBoolean(attr.getValue());
if (!(expr instanceof LitBoolean))
throw new EvaluatorException("Attribute output of the Tag " + tlt.getFullName() + ", must contain a static boolean value (true or false, yes or no)");
// boolean output = ((LitBoolean)expr).getBooleanValue();
// if(!output) ASMUtil.removeLiterlChildren(tag, true);
}
// extends
attr = tag.getAttribute("extends");
if (attr != null) {
Expression expr = tag.getFactory().toExprString(attr.getValue());
if (!(expr instanceof LitString))
throw new EvaluatorException("Attribute extends of the Tag " + tlt.getFullName() + ", must contain a literal string value");
}
// implements
if (isComponent) {
attr = tag.getAttribute("implements");
if (attr != null) {
Expression expr = tag.getFactory().toExprString(attr.getValue());
if (!(expr instanceof LitString))
throw new EvaluatorException("Attribute implements of the Tag " + tlt.getFullName() + ", must contain a literal string value");
}
}
// modifier
if (isComponent) {
attr = tag.getAttribute("modifier");
if (attr != null) {
Expression expr = tag.getFactory().toExprString(attr.getValue());
if (!(expr instanceof LitString))
throw new EvaluatorException("Attribute modifier of the Tag " + tlt.getFullName() + ", must contain a literal string value");
LitString ls = (LitString) expr;
int mod = ComponentUtil.toModifier(ls.getString(), lucee.runtime.Component.MODIFIER_NONE, -1);
if (mod == -1)
throw new EvaluatorException("Value [" + ls.getString() + "] from attribute modifier of the Tag " + tlt.getFullName() + " is invalid,valid values are [none,abstract,final]");
}
}
}
use of lucee.transformer.expression.literal.LitBoolean in project Lucee by lucee.
the class DocCommentTransformer method param.
private Attribute param(Factory factory, ParserString ps) {
String name = paramName(ps);
if (name == null)
return new Attribute(true, "@", factory.TRUE(), "boolean");
// white space
while (ps.isValidIndex() && ps.isCurrentWhiteSpace()) {
if (ps.getCurrent() == '\n')
return new Attribute(true, name, factory.TRUE(), "boolean");
ps.next();
}
Expression value = paramValue(factory, ps);
return new Attribute(true, name, value, value instanceof LitBoolean ? "boolean" : "string");
}
Aggregations