Search in sources :

Example 1 with ClassOrInterfaceTypeContext

use of org.beetl.core.parser.BeetlParser.ClassOrInterfaceTypeContext in project beetl2.0 by javamonkey.

the class AntlrProgramBuilder method parseCommentTag.

protected void parseCommentTag(CommentTypeTagContext typeCtx) {
    List<CommentTypeItemTagContext> list = typeCtx.commentTypeItemTag();
    for (CommentTypeItemTagContext ctx : list) {
        ClassOrInterfaceTypeContext classCtx = ctx.classOrInterfaceType();
        Type type = getClassType(classCtx);
        String globalVarName = ctx.Identifier1().getSymbol().getText();
        this.data.globalType.put(globalVarName, type);
    }
}
Also used : Type(org.beetl.core.statement.Type) CommentTypeItemTagContext(org.beetl.core.parser.BeetlParser.CommentTypeItemTagContext) ClassOrInterfaceTypeContext(org.beetl.core.parser.BeetlParser.ClassOrInterfaceTypeContext)

Example 2 with ClassOrInterfaceTypeContext

use of org.beetl.core.parser.BeetlParser.ClassOrInterfaceTypeContext in project beetl2.0 by javamonkey.

the class AntlrProgramBuilder method getClassType.

private Type getClassType(ClassOrInterfaceTypeContext ctx) {
    List<TerminalNode> list = ctx.Identifier1();
    String className = this.getID(list);
    Class cls = gt.loadClassBySimpleName(className);
    if (cls == null) {
        BeetlException ex = new BeetlException(BeetlException.TYPE_SEARCH_ERROR, className);
        ex.pushToken(this.getBTToken(ctx.getStart()));
        throw ex;
    }
    Type classType = new Type(cls);
    TypeArgumentsContext typeArgCtx = ctx.typeArguments();
    if (typeArgCtx != null) {
        List<TypeArgumentContext> listType = typeArgCtx.typeArgument();
        if (listType != null) {
            Type[] subType = new Type[listType.size()];
            int i = 0;
            for (TypeArgumentContext typeCtx : listType) {
                ClassOrInterfaceTypeContext child = typeCtx.classOrInterfaceType();
                Type type = this.getClassType(child);
                subType[i++] = type;
            }
            classType.types = subType;
        }
    }
    return classType;
}
Also used : BeetlException(org.beetl.core.exception.BeetlException) Type(org.beetl.core.statement.Type) ClassOrInterfaceTypeContext(org.beetl.core.parser.BeetlParser.ClassOrInterfaceTypeContext) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode) TypeArgumentContext(org.beetl.core.parser.BeetlParser.TypeArgumentContext) TypeArgumentsContext(org.beetl.core.parser.BeetlParser.TypeArgumentsContext)

Aggregations

ClassOrInterfaceTypeContext (org.beetl.core.parser.BeetlParser.ClassOrInterfaceTypeContext)2 Type (org.beetl.core.statement.Type)2 TerminalNode (org.antlr.v4.runtime.tree.TerminalNode)1 BeetlException (org.beetl.core.exception.BeetlException)1 CommentTypeItemTagContext (org.beetl.core.parser.BeetlParser.CommentTypeItemTagContext)1 TypeArgumentContext (org.beetl.core.parser.BeetlParser.TypeArgumentContext)1 TypeArgumentsContext (org.beetl.core.parser.BeetlParser.TypeArgumentsContext)1