Search in sources :

Example 11 with TemplateGroup

use of com.eprosima.idl.generator.manager.TemplateGroup in project ihmc-pub-sub by ihmcrobotics.

the class IDLParser method except_decl.

public final Except_declContext except_decl() throws RecognitionException {
    Except_declContext _localctx = new Except_declContext(_ctx, getState());
    enterRule(_localctx, 192, RULE_except_decl);
    String name = null;
    com.eprosima.idl.parser.tree.Exception exceptionObject = null;
    TemplateGroup exTemplates = null;
    Token tk = null;
    try {
        enterOuterAlt(_localctx, 1);
        {
            setState(1162);
            match(KW_EXCEPTION);
            tk = _input.LT(1);
            setState(1164);
            ((Except_declContext) _localctx).identifier = identifier();
            name = ((Except_declContext) _localctx).identifier.id;
            // Create the Exception object.
            exceptionObject = ctx.createException(name, tk);
            if (ctx.isInScopedFile() || ctx.isScopeLimitToAll()) {
                if (tmanager != null) {
                    exTemplates = tmanager.createTemplateGroup("exception");
                    exTemplates.setAttribute("ctx", ctx);
                    // Set the the exception object to the TemplateGroup of the module.
                    exTemplates.setAttribute("exception", exceptionObject);
                }
            } else // Its a dependency.
            {
                ctx.addIncludeDependency(ctx.getScopeFile());
            }
            setState(1167);
            match(LEFT_BRACE);
            setState(1168);
            opt_member_list(exceptionObject);
            setState(1169);
            match(RIGHT_BRACE);
            // Create the returned data.
            ((Except_declContext) _localctx).returnPair = new Pair<com.eprosima.idl.parser.tree.Exception, TemplateGroup>(exceptionObject, exTemplates);
        }
    } catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    } finally {
        exitRule();
    }
    return _localctx;
}
Also used : TemplateGroup(com.eprosima.idl.generator.manager.TemplateGroup) org.antlr.v4.runtime.tree(org.antlr.v4.runtime.tree) com.eprosima.idl.parser.tree(com.eprosima.idl.parser.tree) Pair(com.eprosima.idl.util.Pair)

Example 12 with TemplateGroup

use of com.eprosima.idl.generator.manager.TemplateGroup in project ihmc-pub-sub by ihmcrobotics.

the class IDLParser method struct_type.

public final Struct_typeContext struct_type() throws RecognitionException {
    Struct_typeContext _localctx = new Struct_typeContext(_ctx, getState());
    enterRule(_localctx, 154, RULE_struct_type);
    String name = null;
    Vector<TypeCode> vector = null;
    StructTypeCode structTP = null;
    TemplateGroup structTemplates = null;
    Token tk = null;
    String comments = null;
    try {
        enterOuterAlt(_localctx, 1);
        {
            setState(995);
            match(KW_STRUCT);
            setState(996);
            ((Struct_typeContext) _localctx).identifier = identifier();
            tk = _input.LT(1);
            comments = ctx.lookForComments(_input, tk, 50);
            name = ((Struct_typeContext) _localctx).identifier.id;
            structTP = ctx.createStructTypeCode(name, comments);
            for (ConstDeclaration constDeclaration : constDeclarations) structTP.addConstant(constDeclaration);
            constDeclarations.clear();
            setState(998);
            match(LEFT_BRACE);
            setState(999);
            member_list(structTP);
            setState(1000);
            match(RIGHT_BRACE);
            if (ctx.isInScopedFile() || ctx.isScopeLimitToAll()) {
                if (tmanager != null) {
                    structTemplates = tmanager.createTemplateGroup("struct_type");
                    structTemplates.setAttribute("ctx", ctx);
                    structTemplates.setAttribute("struct", structTP);
                }
            }
            // Return the returned data.
            vector = new Vector<TypeCode>();
            vector.add(structTP);
            ((Struct_typeContext) _localctx).returnPair = new Pair<Vector<TypeCode>, TemplateGroup>(vector, structTemplates);
        }
    } catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    } finally {
        exitRule();
    }
    return _localctx;
}
Also used : TemplateGroup(com.eprosima.idl.generator.manager.TemplateGroup) Vector(java.util.Vector) Pair(com.eprosima.idl.util.Pair)

Example 13 with TemplateGroup

use of com.eprosima.idl.generator.manager.TemplateGroup in project ihmc-pub-sub by ihmcrobotics.

the class IDLParser method annotation_def.

public final Annotation_defContext annotation_def() throws RecognitionException {
    Annotation_defContext _localctx = new Annotation_defContext(_ctx, getState());
    enterRule(_localctx, 142, RULE_annotation_def);
    TemplateGroup annotationTemplates = null;
    try {
        enterOuterAlt(_localctx, 1);
        {
            setState(958);
            ((Annotation_defContext) _localctx).annotation_header = annotation_header();
            setState(959);
            match(LEFT_BRACE);
            setState(960);
            annotation_body(((Annotation_defContext) _localctx).annotation_header.annotation);
            setState(961);
            match(RIGHT_BRACE);
            if (((Annotation_defContext) _localctx).annotation_header.annotation != null) {
                if (ctx.isInScopedFile() || ctx.isScopeLimitToAll()) {
                    if (tmanager != null) {
                        annotationTemplates = tmanager.createTemplateGroup("annotation");
                        annotationTemplates.setAttribute("ctx", ctx);
                        // Set the annotation object to the TemplateGroup of the annotation.
                        annotationTemplates.setAttribute("annotation", ((Annotation_defContext) _localctx).annotation_header.annotation);
                    }
                }
                ((Annotation_defContext) _localctx).returnPair = new Pair<AnnotationDeclaration, TemplateGroup>(((Annotation_defContext) _localctx).annotation_header.annotation, annotationTemplates);
            }
        }
    } catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    } finally {
        exitRule();
    }
    return _localctx;
}
Also used : TemplateGroup(com.eprosima.idl.generator.manager.TemplateGroup) Pair(com.eprosima.idl.util.Pair)

Example 14 with TemplateGroup

use of com.eprosima.idl.generator.manager.TemplateGroup in project ihmc-pub-sub by ihmcrobotics.

the class TemplateManager method createTemplateGroup.

public TemplateGroup createTemplateGroup(String templatename) {
    TemplateGroup tg = new TemplateGroup();
    Set<Entry<String, StringTemplateGroup>> set = m_groups.entrySet();
    Iterator<Entry<String, StringTemplateGroup>> it = set.iterator();
    while (it.hasNext()) {
        Map.Entry<String, StringTemplateGroup> m = (Map.Entry<String, StringTemplateGroup>) it.next();
        // Obtain instance
        StringTemplate template = m.getValue().getInstanceOf(templatename);
        if (!m_extensions.containsKey(m.getKey() + "_" + template.getName())) {
            tg.addTemplate(m.getKey(), template);
        } else {
            List<TemplateExtension> extensions = m_extensions.get(m.getKey() + "_" + template.getName());
            List<StringTemplate> extensionstemplates = new ArrayList<StringTemplate>();
            for (TemplateExtension extension : extensions) {
                extensionstemplates.add(extension.createStringTemplate());
            }
            tg.addTemplate(m.getKey(), template, extensionstemplates);
        }
    }
    return tg;
}
Also used : ArrayList(java.util.ArrayList) Entry(java.util.Map.Entry) TemplateGroup(com.eprosima.idl.generator.manager.TemplateGroup) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

TemplateGroup (com.eprosima.idl.generator.manager.TemplateGroup)14 Pair (com.eprosima.idl.util.Pair)11 Vector (java.util.Vector)5 com.eprosima.idl.parser.tree (com.eprosima.idl.parser.tree)2 ArrayList (java.util.ArrayList)2 org.antlr.v4.runtime.tree (org.antlr.v4.runtime.tree)2 TemplateManager (com.eprosima.idl.generator.manager.TemplateManager)1 ParseException (com.eprosima.idl.parser.exception.ParseException)1 IDLLexer (com.eprosima.idl.parser.grammar.IDLLexer)1 IDLParser (com.eprosima.idl.parser.grammar.IDLParser)1 DefaultErrorListener (com.eprosima.idl.parser.listener.DefaultErrorListener)1 AnnotationDeclaration (com.eprosima.idl.parser.tree.AnnotationDeclaration)1 AnnotationMember (com.eprosima.idl.parser.tree.AnnotationMember)1 PrimitiveTypeCode (com.eprosima.idl.parser.typecode.PrimitiveTypeCode)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1