Package net.percederberg.grammatica.code.java

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


            modifiers = JavaClass.PACKAGE_LOCAL;
        }
        this.cls = new JavaClass(modifiers,
                                 gen.getBaseName() + "Tokenizer",
                                 "Tokenizer");
        this.initMethod = new JavaMethod(JavaMethod.PRIVATE,
                                         "createPatterns",
                                         "",
                                         "void");
        initializeCode();
    }
View Full Code Here


            modifiers = JavaClass.PACKAGE_LOCAL + JavaClass.ABSTRACT;
        }
        this.cls = new JavaClass(modifiers,
                                 gen.getBaseName() + "Analyzer",
                                 "Analyzer");
        this.enter = new JavaMethod(JavaMethod.PROTECTED,
                                    "enter",
                                    "Node node",
                                    "void");
        this.exit = new JavaMethod(JavaMethod.PROTECTED,
                                   "exit",
                                   "Node node",
                                   "Node");
        this.child = new JavaMethod(JavaMethod.PROTECTED,
                                    "child",
                                    "Production node, Node child",
                                    "void");
        initializeCode();
    }
View Full Code Here

     *
     * @param name           the node name
     * @param type           the node type
     */
    private void addEnterMethod(String name, String type) {
        JavaMethod  m;

        m = new JavaMethod(JavaMethod.PROTECTED,
                           "enter" + name,
                           type + " node",
                           "void");
        m.addComment(new JavaComment(ENTER_COMMENT));
        m.addThrows("ParseException");
        cls.addMethod(m);
    }
View Full Code Here

     *
     * @param name           the node name
     * @param type           the node type
     */
    private void addExitMethod(String name, String type) {
        JavaMethod  m;

        m = new JavaMethod(JavaMethod.PROTECTED,
                           "exit" + name,
                           type + " node",
                           "Node");
        m.addComment(new JavaComment(EXIT_COMMENT));
        m.addThrows("ParseException");
        m.addCode("return node;");
        cls.addMethod(m);
    }
View Full Code Here

     * Adds an add child method to this file.
     *
     * @param name           the node name
     */
    private void addChildMethod(String name) {
        JavaMethod  m;

        m = new JavaMethod(JavaMethod.PROTECTED,
                           "child" + name,
                           "Production node, Node child",
                           "void");
        m.addComment(new JavaComment(CHILD_COMMENT));
        m.addThrows("ParseException");
        m.addCode("node.addChild(child);");
        cls.addMethod(m);
    }
View Full Code Here

            modifiers = JavaClass.PACKAGE_LOCAL;
        }
        this.cls = new JavaClass(modifiers,
                                 gen.getBaseName() + "Parser",
                                 "RecursiveDescentParser");
        this.initMethod = new JavaMethod(JavaMethod.PRIVATE,
                                         "createPatterns",
                                         "",
                                         "void");
        initializeCode(tokenizer, analyzer);
    }
View Full Code Here

     */
    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",
                                "Tokenizer");
        method.addThrows("ParserCreationException");
        method.addComment(new JavaComment(FACTORY_COMMENT));
        method.addCode("return new " + tokenizer.getClassName() + "(in);");
        cls.addMethod(method);

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

TOP

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

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.