use of edu.princeton.cs.algs4.ST in project antlr4 by tunnelvisionlabs.
the class DefaultToolListener method error.
@Override
public void error(ANTLRMessage msg) {
ST msgST = tool.errMgr.getMessageTemplate(msg);
String outputMsg = msgST.render();
if (tool.errMgr.formatWantsSingleLineMessage()) {
outputMsg = outputMsg.replace('\n', ' ');
}
System.err.println(outputMsg);
}
use of edu.princeton.cs.algs4.ST in project antlr4 by tunnelvisionlabs.
the class TestRuleVersioning method testPropertyEvaluation.
@Test
public void testPropertyEvaluation() throws Exception {
Properties properties = getProperties();
assertNotNull(properties);
STGroup group = createGroup(properties);
assertNotNull(group);
Set<String> templateNames = group.getTemplateNames();
String templateName0 = "/PropertyEval0-sample-template";
assertTrue(templateNames.contains(templateName0));
ST st = group.getInstanceOf(templateName0);
assertNotNull(st);
String result = st.render();
assertEquals("foo", result);
String templateName1 = "/PropertyEval1-sample-template";
assertTrue(templateNames.contains(templateName1));
ST st1 = group.getInstanceOf(templateName1);
assertNotNull(st1);
String result1 = st1.render();
assertEquals("foo", result1);
assertEquals("foo", resolveProperty(properties, group, "PropertyEval0", "sample"));
assertEquals("foo", resolveProperty(properties, group, "PropertyEval1", "sample"));
assertEquals("foo", resolveProperty(properties, group, "PropertyEval2", "sample"));
assertEquals("foo", resolveProperty(properties, group, "PropertyEval3", "sample"));
assertEquals("foo", resolveProperty(properties, group, "PropertyEval4", "sample"));
assertEquals("foo", resolveProperty(properties, group, "PropertyEval5", "sample"));
}
use of edu.princeton.cs.algs4.ST in project antlr4 by tunnelvisionlabs.
the class Antlr4ErrorLog method warning.
/**
* {@inheritDoc}
* <p>
* This implementation passes the message to the Maven log.
* </p>
* @param message
*/
@Override
public void warning(ANTLRMessage message) {
ST msgST = tool.errMgr.getMessageTemplate(message);
String outputMsg = msgST.render();
if (tool.errMgr.formatWantsSingleLineMessage()) {
outputMsg = outputMsg.replace('\n', ' ');
}
log.warn(outputMsg);
if (message.fileName != null) {
String text = message.getMessageTemplate(false).render();
buildContext.addMessage(new File(message.fileName), message.line, message.charPosition, text, BuildContext.SEVERITY_WARNING, message.getCause());
}
}
use of edu.princeton.cs.algs4.ST in project antlr4 by tunnelvisionlabs.
the class Antlr4ErrorLog method error.
/**
* {@inheritDoc}
* <p>
* This implementation passes the message to the Maven log.
* </p>
* @param message The message to send to Maven.
*/
@Override
public void error(ANTLRMessage message) {
ST msgST = tool.errMgr.getMessageTemplate(message);
String outputMsg = msgST.render();
if (tool.errMgr.formatWantsSingleLineMessage()) {
outputMsg = outputMsg.replace('\n', ' ');
}
log.error(outputMsg);
if (message.fileName != null) {
String text = message.getMessageTemplate(false).render();
buildContext.addMessage(new File(message.fileName), message.line, message.charPosition, text, BuildContext.SEVERITY_ERROR, message.getCause());
}
}
use of edu.princeton.cs.algs4.ST in project antlr4 by tunnelvisionlabs.
the class TestGenerator method generateTestFile.
protected void generateTestFile(STGroup index, STGroup targetGroup, String testdir, Collection<String> testTemplates) {
ErrorBuffer errors = new ErrorBuffer();
targetGroup.setListener(errors);
File targetFolder = getOutputDir(testdir);
String testName = testdir.substring(testdir.lastIndexOf('/') + 1);
File targetFile = new File(targetFolder, "Test" + testName + ".java");
// System.out.println("Generating file "+targetFile.getAbsolutePath());
List<ST> templates = new ArrayList<ST>();
for (String template : testTemplates) {
STGroup testGroup = new STGroupFile(testdir + "/" + template + STGroup.GROUP_FILE_EXTENSION);
importLanguageTemplates(testGroup, targetGroup);
ST testType = testGroup.getInstanceOf("TestType");
if (testType == null) {
warn(String.format("Unable to generate tests for %s: no TestType specified.", template));
continue;
}
ST testMethodTemplate = targetGroup.getInstanceOf(testType.render() + "TestMethod");
if (testMethodTemplate == null) {
warn(String.format("Unable to generate tests for %s: TestType '%s' is not supported by the current runtime.", template, testType.render()));
continue;
}
testMethodTemplate.add(testMethodTemplate.impl.formalArguments.keySet().iterator().next(), testGroup);
templates.add(testMethodTemplate);
}
ST testFileTemplate = targetGroup.getInstanceOf("TestFile");
testFileTemplate.addAggr("file.{Options,name,tests}", index.rawGetDictionary("Options"), testName, templates);
if (visualize) {
STViz viz = testFileTemplate.inspect();
try {
viz.waitForClose();
} catch (InterruptedException ex) {
}
}
try {
String output = testFileTemplate.render();
if (errors.errors.size() > 0) {
System.err.println("errors in " + targetGroup.getName() + ": " + errors);
}
writeFile(targetFile, output);
} catch (IOException ex) {
error(String.format("Failed to write output file: %s", targetFile), ex);
}
}
Aggregations