use of org.stringtemplate.v4.STGroupFile in project antlr4 by tunnelvisionlabs.
the class LeftRecursiveRuleAnalyzer method loadPrecRuleTemplates.
public void loadPrecRuleTemplates() {
String templateGroupFile = "org/antlr/v4/tool/templates/LeftRecursiveRules.stg";
recRuleTemplates = new STGroupFile(templateGroupFile);
if (!recRuleTemplates.isDefined("recRule")) {
tool.errMgr.toolError(ErrorType.MISSING_CODE_GEN_TEMPLATES, "LeftRecursiveRules");
}
// use codegen to get correct language templates; that's it though
CodeGenerator gen = new CodeGenerator(tool, null, language);
STGroup templates = gen.getTemplates();
if (templates == null) {
// this class will still operate using Java templates
templates = new CodeGenerator(tool, null, "Java").getTemplates();
assert templates != null;
}
codegenTemplates = templates;
}
use of org.stringtemplate.v4.STGroupFile in project antlr4 by tunnelvisionlabs.
the class Target method loadTemplates.
@NotNull
protected STGroup loadTemplates() {
STGroup result = new STGroupFile(CodeGenerator.TEMPLATE_ROOT + "/" + getLanguage() + "/" + getLanguage() + STGroup.GROUP_FILE_EXTENSION);
result.registerRenderer(Integer.class, new NumberRenderer());
result.registerRenderer(String.class, new StringRenderer());
result.setListener(new STErrorListener() {
@Override
public void compileTimeError(STMessage msg) {
reportError(msg);
}
@Override
public void runTimeError(STMessage msg) {
reportError(msg);
}
@Override
public void IOError(STMessage msg) {
reportError(msg);
}
@Override
public void internalError(STMessage msg) {
reportError(msg);
}
private void reportError(STMessage msg) {
getCodeGenerator().tool.errMgr.toolError(ErrorType.STRING_TEMPLATE_WARNING, msg.cause, msg.toString());
}
});
return result;
}
use of org.stringtemplate.v4.STGroupFile in project killbill by killbill.
the class TestStringTemplateInheritance method testCheckQueries.
@Test(groups = "fast")
public void testCheckQueries() throws Exception {
final STGroup kombucha = new STGroupFile(this.getClass().getResource("/org/killbill/billing/util/dao/Kombucha.sql.stg"), "UTF-8", '<', '>');
// Verify non inherited template
Assert.assertEquals(kombucha.getInstanceOf("isItTimeForKombucha").render(), "select count(*) = 0 as is_time from kombucha;");
// Verify inherited templates
assertPattern(kombucha.getInstanceOf("getById").render(), "select\r?\n" + " t.record_id\r?\n" + ", t.id\r?\n" + ", t.tea\r?\n" + ", t.mushroom\r?\n" + ", t.sugar\r?\n" + ", t.account_record_id\r?\n" + ", t.tenant_record_id\r?\n" + "from kombucha t\r?\n" + "where t.id = :id\r?\n" + "and t.tenant_record_id = :tenantRecordId\r?\n" + ";");
assertPattern(kombucha.getInstanceOf("getByRecordId").render(), "select\r?\n" + " t.record_id\r?\n" + ", t.id\r?\n" + ", t.tea\r?\n" + ", t.mushroom\r?\n" + ", t.sugar\r?\n" + ", t.account_record_id\r?\n" + ", t.tenant_record_id\r?\n" + "from kombucha t\r?\n" + "where t.record_id = :recordId\r?\n" + "and t.tenant_record_id = :tenantRecordId\r?\n" + ";");
assertPattern(kombucha.getInstanceOf("getRecordId").render(), "select\r?\n" + " t.record_id\r?\n" + "from kombucha t\r?\n" + "where t.id = :id\r?\n" + "and t.tenant_record_id = :tenantRecordId\r?\n" + ";");
assertPattern(kombucha.getInstanceOf("getHistoryRecordId").render(), "select\r?\n" + " max\\(t.record_id\\)\r?\n" + "from kombucha_history t\r?\n" + "where t.target_record_id = :targetRecordId\r?\n" + "and t.tenant_record_id = :tenantRecordId\r?\n" + ";");
assertPattern(kombucha.getInstanceOf("getAll").render(), "select\r?\n" + " t.record_id\r?\n" + ", t.id\r?\n" + ", t.tea\r?\n" + ", t.mushroom\r?\n" + ", t.sugar\r?\n" + ", t.account_record_id\r?\n" + ", t.tenant_record_id\r?\n" + "from kombucha t\r?\n" + "where t.tenant_record_id = :tenantRecordId\r?\n" + "order by t.record_id ASC\r?\n" + ";");
assertPattern(kombucha.getInstanceOf("get").add("orderBy", "record_id").add("offset", "3").add("rowCount", "12").add("ordering", "ASC").render(), "select\r?\n" + " t.record_id\r?\n" + ", t.id\r?\n" + ", t.tea\r?\n" + ", t.mushroom\r?\n" + ", t.sugar\r?\n" + ", t.account_record_id\r?\n" + ", t.tenant_record_id\r?\n" + "from kombucha t\r?\n" + "join \\(\r?\n" + " select record_id\r?\n" + " from kombucha\r?\n" + " where tenant_record_id = :tenantRecordId\r?\n" + " order by record_id ASC\r?\n" + " limit :rowCount offset :offset\r?\n" + "\\) optimization on optimization.record_id = t.record_id\r?\n" + "order by t.record_id ASC\r?\n" + ";");
assertPattern(kombucha.getInstanceOf("test").render(), "select\r?\n" + " t.record_id\r?\n" + ", t.id\r?\n" + ", t.tea\r?\n" + ", t.mushroom\r?\n" + ", t.sugar\r?\n" + ", t.account_record_id\r?\n" + ", t.tenant_record_id\r?\n" + "from kombucha t\r?\n" + "where t.tenant_record_id = :tenantRecordId\r?\n" + "limit 1\r?\n" + ";");
assertPattern(kombucha.getInstanceOf("addHistoriesFromTransaction").render(), "insert into kombucha_history \\(\r?\n" + " id\r?\n" + ", target_record_id\r?\n" + ", change_type\r?\n" + ", tea\r?\n" + ", mushroom\r?\n" + ", sugar\r?\n" + ", account_record_id\r?\n" + ", tenant_record_id\r?\n" + "\\)\r?\n" + "values \\(\r?\n" + " :id\r?\n" + ", :targetRecordId\r?\n" + ", :changeType\r?\n" + ", :tea\r?\n" + ", :mushroom\r?\n" + ", :sugar\r?\n" + ", :accountRecordId\r?\n" + ", :tenantRecordId\r?\n" + "\\)\r?\n" + ";");
assertPattern(kombucha.getInstanceOf("insertAuditsFromTransaction").render(), "insert into audit_log \\(\r?\n" + "id\r?\n" + ", table_name\r?\n" + ", target_record_id\r?\n" + ", change_type\r?\n" + ", created_by\r?\n" + ", reason_code\r?\n" + ", comments\r?\n" + ", user_token\r?\n" + ", created_date\r?\n" + ", account_record_id\r?\n" + ", tenant_record_id\r?\n" + "\\)\r?\n" + "values \\(\r?\n" + " :id\r?\n" + ", :tableName\r?\n" + ", :targetRecordId\r?\n" + ", :changeType\r?\n" + ", :createdBy\r?\n" + ", :reasonCode\r?\n" + ", :comments\r?\n" + ", :userToken\r?\n" + ", :createdDate\r?\n" + ", :accountRecordId\r?\n" + ", :tenantRecordId\r?\n" + "\\)\r?\n" + ";");
}
use of org.stringtemplate.v4.STGroupFile in project antlr4 by antlr.
the class LeftRecursiveRuleAnalyzer method loadPrecRuleTemplates.
public void loadPrecRuleTemplates() {
String templateGroupFile = "org/antlr/v4/tool/templates/LeftRecursiveRules.stg";
recRuleTemplates = new STGroupFile(templateGroupFile);
if (!recRuleTemplates.isDefined("recRule")) {
tool.errMgr.toolError(ErrorType.MISSING_CODE_GEN_TEMPLATES, "LeftRecursiveRules");
}
// use codegen to get correct language templates; that's it though
CodeGenerator gen = new CodeGenerator(tool, null, language);
codegenTemplates = gen.getTemplates();
}
use of org.stringtemplate.v4.STGroupFile in project antlr4 by antlr.
the class CSharpTarget method loadTemplates.
@Override
protected STGroup loadTemplates() {
// override the superclass behavior to put all C# templates in the same folder
STGroup result = new STGroupFile(CodeGenerator.TEMPLATE_ROOT + "/CSharp/" + getLanguage() + STGroup.GROUP_FILE_EXTENSION);
result.registerRenderer(Integer.class, new NumberRenderer());
result.registerRenderer(String.class, new StringRenderer());
result.setListener(new STErrorListener() {
@Override
public void compileTimeError(STMessage msg) {
reportError(msg);
}
@Override
public void runTimeError(STMessage msg) {
reportError(msg);
}
@Override
public void IOError(STMessage msg) {
reportError(msg);
}
@Override
public void internalError(STMessage msg) {
reportError(msg);
}
private void reportError(STMessage msg) {
getCodeGenerator().tool.errMgr.toolError(ErrorType.STRING_TEMPLATE_WARNING, msg.cause, msg.toString());
}
});
return result;
}
Aggregations