Search in sources :

Example 6 with LitBoolean

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]");
        }
    }
}
Also used : Attribute(lucee.transformer.bytecode.statement.tag.Attribute) Statement(lucee.transformer.bytecode.Statement) Page(lucee.transformer.bytecode.Page) LitBoolean(lucee.transformer.expression.literal.LitBoolean) LitString(lucee.transformer.expression.literal.LitString) LitString(lucee.transformer.expression.literal.LitString) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) Expression(lucee.transformer.expression.Expression) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(lucee.transformer.bytecode.statement.tag.Tag) LitBoolean(lucee.transformer.expression.literal.LitBoolean) TagCIObject(lucee.transformer.bytecode.statement.tag.TagCIObject)

Example 7 with LitBoolean

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");
}
Also used : Attribute(lucee.transformer.bytecode.statement.tag.Attribute) Expression(lucee.transformer.expression.Expression) LitBoolean(lucee.transformer.expression.literal.LitBoolean) ParserString(lucee.commons.lang.ParserString)

Aggregations

Expression (lucee.transformer.expression.Expression)7 LitBoolean (lucee.transformer.expression.literal.LitBoolean)7 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)6 LitString (lucee.transformer.expression.literal.LitString)3 Page (lucee.transformer.bytecode.Page)2 AttributeEvaluatorException (lucee.transformer.cfml.attributes.AttributeEvaluatorException)2 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ParserString (lucee.commons.lang.ParserString)1 PageSource (lucee.runtime.PageSource)1 TemplateException (lucee.runtime.exp.TemplateException)1 TransformerException (lucee.transformer.TransformerException)1 Body (lucee.transformer.bytecode.Body)1 Statement (lucee.transformer.bytecode.Statement)1 StaticBody (lucee.transformer.bytecode.StaticBody)1 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)1 Argument (lucee.transformer.bytecode.statement.Argument)1 Tag (lucee.transformer.bytecode.statement.tag.Tag)1 TagCIObject (lucee.transformer.bytecode.statement.tag.TagCIObject)1