Search in sources :

Example 1 with TagCode

use of jetbrick.template.parser.code.TagCode in project jetbrick-template-1x by subchen.

the class JetTemplateCodeVisitor method visitTag_directive.

@Override
public Code visitTag_directive(Tag_directiveContext ctx) {
    String text = ctx.getChild(0).getText();
    String name = text.substring(5, text.length() - 1).trim();
    TagCode tagCode = scopeCode.createTagCode();
    tagCode.setTagId(getUid("tag"));
    scopeCode = tagCode.getMethodCode();
    scopeCode.define(Code.CONTEXT_NAME, TypedKlass.JetContext);
    // add body content
    scopeCode.setBodyCode(ctx.block().accept(this));
    scopeCode = scopeCode.pop();
    // finding tag function
    Expression_listContext expression_list = ctx.expression_list();
    SegmentListCode segmentListCode = (expression_list == null) ? SegmentListCode.EMPTY : (SegmentListCode) expression_list.accept(this);
    Class<?>[] parameterTypes = segmentListCode.getParameterTypes(JetTagContext.class);
    Method method = resolver.resolveTagMethod(name, parameterTypes);
    if (method == null) {
        throw reportError("Undefined tag definition: " + getMethodSignature(name, parameterTypes), ctx);
    }
    tagCode.setMethod(method);
    tagCode.setExpressionListCode(segmentListCode);
    return tagCode;
}
Also used : Expression_listContext(jetbrick.template.parser.grammer.JetTemplateParser.Expression_listContext) TagCode(jetbrick.template.parser.code.TagCode) Method(java.lang.reflect.Method) SegmentListCode(jetbrick.template.parser.code.SegmentListCode)

Aggregations

Method (java.lang.reflect.Method)1 SegmentListCode (jetbrick.template.parser.code.SegmentListCode)1 TagCode (jetbrick.template.parser.code.TagCode)1 Expression_listContext (jetbrick.template.parser.grammer.JetTemplateParser.Expression_listContext)1