Package net.percederberg.grammatica.code.java

Examples of net.percederberg.grammatica.code.java.JavaConstructor


    /**
     * Initializes the source code objects.
     */
    private void initializeCode() {
        JavaConstructor  constr;
        String           str;

        // Add imports
        file.addImport(new JavaImport("java.io", "Reader"));
        file.addImport(new JavaImport("net.percederberg.grammatica.parser",
                                      "ParserCreationException"));
        file.addImport(new JavaImport("net.percederberg.grammatica.parser",
                                      "TokenPattern"));
        file.addImport(new JavaImport("net.percederberg.grammatica.parser",
                                      "Tokenizer"));

        // Add class
        file.addClass(cls);
        str = CLASS_COMMENT;
        if (gen.getClassComment() != null) {
            str += "\n\n" + gen.getClassComment();
        }
        cls.addComment(new JavaComment(str));

        // Add file comment
        str = file.toString() + "\n\n" + gen.getFileComment();
        file.addComment(new JavaComment(JavaComment.BLOCK, str));

        // Add constructor
        constr = new JavaConstructor("Reader input");
        cls.addConstructor(constr);
        constr.addComment(new JavaComment(CONSTRUCTOR_COMMENT));
        constr.addThrows("ParserCreationException");
        constr.addCode("super(input, " +
                       !gen.getGrammar().getCaseSensitive() +
                       ");");
        constr.addCode("createPatterns();");

        // Add init method
        cls.addMethod(initMethod);
        initMethod.addComment(new JavaComment(INIT_METHOD_COMMENT));
        initMethod.addThrows("ParserCreationException");
View Full Code Here


     * @param analyzer       the analyzer file generator
     */
    private void initializeCode(JavaTokenizerFile tokenizer,
                                JavaAnalyzerFile analyzer) {

        JavaConstructor  constr;
        JavaMethod       method;
        String           str;

        // Add imports
        file.addImport(new JavaImport("java.io", "Reader"));
        file.addImport(new JavaImport("net.percederberg.grammatica.parser",
                                      "ParserCreationException"));
        file.addImport(new JavaImport("net.percederberg.grammatica.parser",
                                      "ProductionPattern"));
        file.addImport(new JavaImport("net.percederberg.grammatica.parser",
                                      "ProductionPatternAlternative"));
        file.addImport(new JavaImport("net.percederberg.grammatica.parser",
                                      "RecursiveDescentParser"));
        file.addImport(new JavaImport("net.percederberg.grammatica.parser",
                                      "Tokenizer"));

        // Add class
        file.addClass(cls);
        str = TYPE_COMMENT;
        if (gen.getClassComment() != null) {
            str += "\n\n" + gen.getClassComment();
        }
        cls.addComment(new JavaComment(str));

        // Add file comment
        str = file.toString() + "\n\n" + gen.getFileComment();
        file.addComment(new JavaComment(JavaComment.BLOCK, str));

        // Add constructor
        constr = new JavaConstructor("Reader in");
        cls.addConstructor(constr);
        constr.addComment(new JavaComment(CONSTRUCTOR1_COMMENT));
        constr.addThrows("ParserCreationException");
        constr.addCode("super(in);");
        constr.addCode("createPatterns();");

        // Add constructor
        constr = new JavaConstructor("Reader in, " + analyzer.getClassName() +
                                     " analyzer");
        cls.addConstructor(constr);
        constr.addComment(new JavaComment(CONSTRUCTOR2_COMMENT));
        constr.addThrows("ParserCreationException");
        constr.addCode("super(in, analyzer);");
        constr.addCode("createPatterns();");

        // Add tokenizer factory method
        method = new JavaMethod(JavaMethod.PROTECTED,
                                "newTokenizer",
                                "Reader in",
View Full Code Here

TOP

Related Classes of net.percederberg.grammatica.code.java.JavaConstructor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.