*/
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));