org.stringtemplate.v4.STGroupFile Java Examples

The following examples show how to use org.stringtemplate.v4.STGroupFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Generators.java    From SugarOnRest with MIT License 7 votes vote down vote up
private static STGroupFile getTemplateGroupFile(String templatePath) throws MalformedURLException {

        if (templatePath == null) {
             return null;
        }

        if (!templatePath.contains(".jar!")) {
            return new STGroupFile(templatePath);
        }

        String protocol = "jar:";
        if (templatePath.startsWith(protocol)) {
            protocol = "";
        }

        URL url = new URL(protocol + templatePath);
        return  new STGroupFile(url, "US-ASCII", '%', '%');
    }
 
Example #2
Source File: TemplateHandler.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the {@link STGroupFile} for {@link TemplateHandlerDelegate#getTemplateGroup()}. If
 * {@link #DEBUG} is {@code false}, then the result will be cached.
 */
private STGroupFile createAndMaybeCacheTemplates() {
  // In debug mode, create a new STGroupFile for each request. This makes it possible to test
  // new versions of the templates without restarting buckd.
  if (DEBUG) {
    return createSTGroupFile();
  }

  // In production, cache the GroupFile object for efficiency.
  if (groupFile != null) {
    return groupFile;
  }

  synchronized (this) {
    if (groupFile == null) {
      groupFile = createSTGroupFile();
    }
  }
  return groupFile;
}
 
Example #3
Source File: STViz.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static void test2() throws IOException { // test rig
     String templates =
"t1(q1=\"Some\\nText\") ::= <<\n" +
"<q1>\n" +
">>\n" +
"\n" +
"t2(p1) ::= <<\n" +
"<p1>\n" +
">>\n" +
"\n" +
"main() ::= <<\n" +
"START-<t1()>-END\n" +
"\n" +
"START-<t2(p1=\"Some\\nText\")>-END\n" +
">>\n";

     String tmpdir = System.getProperty("java.io.tmpdir");
     writeFile(tmpdir, "t.stg", templates);
     STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
     ST st = group.getInstanceOf("main");
     STViz viz = st.inspect();
 }
 
Example #4
Source File: TestGenerator.java    From fix-orchestra with Apache License 2.0 6 votes vote down vote up
private void generateFeature(AutoIndentWriter writer, Repository repository, FlowType flow,
    ActorType actor) {
  final STGroupFile stFeatureGroup = new STGroupFile("templates/feature.stg");

  ST st = stFeatureGroup.getInstanceOf("feature");
  st.add("repository", repository);
  st.add("flow", flow);
  st.add("actor", actor);
  st.write(writer, errorListener);
  
  repository.getMessages().getMessage().stream()
  .filter(m -> flow.getName().equals(m.getFlow())).forEach(message -> {
    Responses responses = message.getResponses();
    if (responses != null)
      responses.getResponse().forEach(response -> generateFeatureScenario(writer, stFeatureGroup, repository, actor, message, response));
  });
}
 
Example #5
Source File: TestGenerator.java    From fix-orchestra with Apache License 2.0 6 votes vote down vote up
private void generateFeatureScenario(AutoIndentWriter writer, STGroupFile stFeatureGroup, Repository repository, ActorType actor,
    MessageType message, ResponseType response) {
  ST st = stFeatureGroup.getInstanceOf("scenario");
  st.add("actor", actor);
  st.add("message", message);
  st.add("response", response);
  st.write(writer, errorListener);
  List<Object> messageElements = message.getStructure().getComponentRefOrGroupRefOrFieldRef();
  generateFeatureMessageElements(writer, stFeatureGroup, messageElements);
  List<Object> actions = response.getMessageRefOrAssignOrTrigger();
  for (Object action : actions) {
    if (action instanceof MessageRefType) {
      MessageRefType messageRef = (MessageRefType) action;
      ST stMessage = stFeatureGroup.getInstanceOf("messageRef");
      stMessage.add("actor", actor);
      stMessage.add("messageRef", messageRef);
      stMessage.write(writer, errorListener);

      MessageType responseMessage = findMessage(messageRef.getName(), messageRef.getScenario());
      List<Object> responseMessageElements =
          responseMessage.getStructure().getComponentRefOrGroupRefOrFieldRef();
      generateFeatureMessageElements(writer, stFeatureGroup, responseMessageElements);
    }
  }
}
 
Example #6
Source File: GenDOT.java    From cs652 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static String gen(LinkViz graph) {
    STGroup templates = new STGroupFile("DOT.stg");
    ST fileST = templates.getInstanceOf("file");
    fileST.add("gname", "testgraph");
    for (LinkViz.Link x : graph.links) {
        ST edgeST = templates.getInstanceOf("edge");
        edgeST.add("from", x.from);
        edgeST.add("to", x.to);
        fileST.add("edges", edgeST);
    }
    return fileST.render(); // render (eval) template to text
}
 
Example #7
Source File: STViz.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void test3() throws IOException
{
    String templates = "main() ::= <<\n"+
        "Foo: <{bar};format=\"lower\">\n" +">>\n";
    String tmpdir = System.getProperty("java.io.tmpdir");
    writeFile(tmpdir, "t.stg", templates);
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    ST st = group.getInstanceOf("main");
    st.inspect();
}
 
Example #8
Source File: STViz.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void test1() throws IOException
{ // test rig
    String templates = "method(type,name,locals,args,stats) ::= <<\n"+"public <type> <name>(<args:{a| int <a>}; separator=\", \">) {\n"+"    <if(locals)>int locals[<locals>];<endif>\n"+"    <stats;separator=\"\\n\">\n"+"}\n"+">>\n"+"assign(a,b) ::= \"<a> = <b>;\"\n"+"return(x) ::= <<return <x>;>>\n"+"paren(x) ::= \"(<x>)\"\n";
    String tmpdir = System.getProperty("java.io.tmpdir");
    writeFile(tmpdir, "t.stg", templates);
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    ST st = group.getInstanceOf("method");
    st.impl.dump();
    st.add("type", "float");
    st.add("name", "foo");
    st.add("locals", 3);
    st.add("args", new String[] {"x",
                                 "y",
                                 "z"});
    ST s1 = group.getInstanceOf("assign");
    ST paren = group.getInstanceOf("paren");
    paren.add("x", "x");
    s1.add("a", paren);
    s1.add("b", "y");
    ST s2 = group.getInstanceOf("assign");
    s2.add("a", "y");
    s2.add("b", "z");
    ST s3 = group.getInstanceOf("return");
    s3.add("x", "3.14159");
    st.add("stats", s1);
    st.add("stats", s2);
    st.add("stats", s3);
    STViz viz = st.inspect();
    System.out.println(st.render()); // should not mess up ST event lists
}
 
Example #9
Source File: STViz.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void test2() throws IOException
{ // test rig
    String templates = "t1(q1=\"Some\\nText\") ::= <<\n"+"<q1>\n"+">>\n"+"\n"+"t2(p1) ::= <<\n"+
                       "<p1>\n"+
                       ">>\n"+
                       "\n" +"main() ::= <<\n"+"START-<t1()>-END\n"+"\n"+"START-<t2(p1=\"Some\\nText\")>-END\n"+">>\n";
    String tmpdir = System.getProperty("java.io.tmpdir");
    writeFile(tmpdir, "t.stg", templates);
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    ST st = group.getInstanceOf("main");
    STViz viz = st.inspect();
}
 
Example #10
Source File: STViz.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void test3() throws IOException {
     String templates =
"main() ::= <<\n" +
"Foo: <{bar};format=\"lower\">\n" +
">>\n";

     String tmpdir = System.getProperty("java.io.tmpdir");
     writeFile(tmpdir, "t.stg", templates);
     STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
     ST st = group.getInstanceOf("main");
     st.inspect();
 }
 
Example #11
Source File: GenDOT.java    From cs652 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static String gen2(LinkViz graph) {
    STGroup templates = new STGroupFile("DOT2.stg");
    ST fileST = templates.getInstanceOf("file");
    fileST.add("gname", "testgraph");
    fileST.add("graph", graph);
    return fileST.render(); // render (eval) template to text
}
 
Example #12
Source File: STViz.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void test3() throws IOException
{
    String templates = "main() ::= <<\n"+
                       "Foo: <{bar};format=\"lower\">\n" +">>\n";
    String tmpdir = System.getProperty("java.io.tmpdir");
    writeFile(tmpdir, "t.stg", templates);
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    ST st = group.getInstanceOf("main");
    st.inspect();
}
 
Example #13
Source File: GenC.java    From cs652 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args) {
	STGroup templates = new STGroupFile("C.stg");
	ST fileST = templates.getInstanceOf("file");
	fileST.add("name", "Foo");
	fileST.add("fields", new Field("i", "int"));
	fileST.add("fields", new Field("j", "float"));
	System.out.println(fileST.render());
}
 
Example #14
Source File: StCompiler.java    From protostuff-compiler with Apache License 2.0 5 votes vote down vote up
/**
 * Create new {@link StCompiler} instance.
 */
@Inject
public StCompiler(OutputStreamFactory outputStreamFactory,
                  @Assisted String templateFileName) {
    super(outputStreamFactory);
    STGroup group = new STGroupFile(templateFileName);
    group.setListener(new StErrorListener());
    this.stGroup = group;
}
 
Example #15
Source File: GenC.java    From cs652 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args) {
	STGroup templates = new STGroupFile("C.stg");
	ST fileST = templates.getInstanceOf("file");
	fileST.add("name", "Foo");
	fileST.add("fields", new Field("i", "int"));
	fileST.add("fields", new Field("j", "float"));
	System.out.println(fileST.render());
}
 
Example #16
Source File: GenDOT.java    From cs652 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static String gen(LinkViz graph) {
    STGroup templates = new STGroupFile("DOT.stg");
    ST fileST = templates.getInstanceOf("file");
    fileST.add("gname", "testgraph");
    for (LinkViz.Link x : graph.links) {
        ST edgeST = templates.getInstanceOf("edge");
        edgeST.add("from", x.from);
        edgeST.add("to", x.to);
        fileST.add("edges", edgeST);
    }
    return fileST.render(); // render (eval) template to text
}
 
Example #17
Source File: StateGenerator.java    From fix-orchestra with Apache License 2.0 5 votes vote down vote up
public StateGenerator(InputStream inputStream, Path rootPath, String srcPackage,
    PrintStream errorStream) {
  this.srcPath = rootPath;
  this.srcPackage = srcPackage;
  this.stGroup = new STGroupFile("templates/stategen.stg", '$', '$');
  // STGroup.verbose = true;
  this.inputStream = inputStream;
  this.errorStream = errorStream;
}
 
Example #18
Source File: STViz.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void test1() throws IOException
{ // test rig
    String templates = "method(type,name,locals,args,stats) ::= <<\n"+"public <type> <name>(<args:{a| int <a>}; separator=\", \">) {\n"+"    <if(locals)>int locals[<locals>];<endif>\n"+"    <stats;separator=\"\\n\">\n"+"}\n"+">>\n"+"assign(a,b) ::= \"<a> = <b>;\"\n"+"return(x) ::= <<return <x>;>>\n"+"paren(x) ::= \"(<x>)\"\n";
    String tmpdir = System.getProperty("java.io.tmpdir");
    writeFile(tmpdir, "t.stg", templates);
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    ST st = group.getInstanceOf("method");
    st.impl.dump();
    st.add("type", "float");
    st.add("name", "foo");
    st.add("locals", 3);
    st.add("args", new String[] {"x",
                                 "y",
                                 "z"});
    ST s1 = group.getInstanceOf("assign");
    ST paren = group.getInstanceOf("paren");
    paren.add("x", "x");
    s1.add("a", paren);
    s1.add("b", "y");
    ST s2 = group.getInstanceOf("assign");
    s2.add("a", "y");
    s2.add("b", "z");
    ST s3 = group.getInstanceOf("return");
    s3.add("x", "3.14159");
    st.add("stats", s1);
    st.add("stats", s2);
    st.add("stats", s3);
    STViz viz = st.inspect();
    System.out.println(st.render()); // should not mess up ST event lists
}
 
Example #19
Source File: STViz.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void test2() throws IOException
{ // test rig
    String templates = "t1(q1=\"Some\\nText\") ::= <<\n"+
                       "<q1>\n" +">>\n"+"\n"+"t2(p1) ::= <<\n"+
                       "<p1>\n"+
                       ">>\n"+
                       "\n"+
                       "main() ::= <<\n" +"START-<t1()>-END\n"+"\n"+"START-<t2(p1=\"Some\\nText\")>-END\n"+">>\n";
    String tmpdir = System.getProperty("java.io.tmpdir");
    writeFile(tmpdir, "t.stg", templates);
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    ST st = group.getInstanceOf("main");
    STViz viz = st.inspect();
}
 
Example #20
Source File: STViz.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void test1() throws IOException
{ // test rig
    String templates = "method(type,name,locals,args,stats) ::= <<\n"+"public <type> <name>(<args:{a| int <a>}; separator=\", \">) {\n"+"    <if(locals)>int locals[<locals>];<endif>\n"+"    <stats;separator=\"\\n\">\n"+"}\n"+">>\n"+"assign(a,b) ::= \"<a> = <b>;\"\n"+"return(x) ::= <<return <x>;>>\n"+"paren(x) ::= \"(<x>)\"\n";
    String tmpdir = System.getProperty("java.io.tmpdir");
    writeFile(tmpdir, "t.stg", templates);
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    ST st = group.getInstanceOf("method");
    st.impl.dump();
    st.add("type", "float");
    st.add("name", "foo");
    st.add("locals", 3);
    st.add("args", new String[] {"x",
                                 "y",
                                 "z"});
    ST s1 = group.getInstanceOf("assign");
    ST paren = group.getInstanceOf("paren");
    paren.add("x", "x");
    s1.add("a", paren);
    s1.add("b", "y");
    ST s2 = group.getInstanceOf("assign");
    s2.add("a", "y");
    s2.add("b", "z");
    ST s3 = group.getInstanceOf("return");
    s3.add("x", "3.14159");
    st.add("stats", s1);
    st.add("stats", s2);
    st.add("stats", s3);
    STViz viz = st.inspect();
    System.out.println(st.render()); // should not mess up ST event lists
}
 
Example #21
Source File: STViz.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void test2() throws IOException
{ // test rig
    String templates = "t1(q1=\"Some\\nText\") ::= <<\n"+
                       "<q1>\n" +">>\n"+"\n"+"t2(p1) ::= <<\n"+
                       "<p1>\n"+
                       ">>\n"+
                       "\n"+
                       "main() ::= <<\n" +"START-<t1()>-END\n"+"\n"+"START-<t2(p1=\"Some\\nText\")>-END\n"+">>\n";
    String tmpdir = System.getProperty("java.io.tmpdir");
    writeFile(tmpdir, "t.stg", templates);
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    ST st = group.getInstanceOf("main");
    STViz viz = st.inspect();
}
 
Example #22
Source File: STViz.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void test2() throws IOException
{ // test rig
    String templates = "t1(q1=\"Some\\nText\") ::= <<\n"+
                       "<q1>\n" +">>\n"+"\n"+"t2(p1) ::= <<\n"+
                       "<p1>\n"+
                       ">>\n"+
                       "\n"+
                       "main() ::= <<\n" +"START-<t1()>-END\n"+"\n"+"START-<t2(p1=\"Some\\nText\")>-END\n"+">>\n";
    String tmpdir = System.getProperty("java.io.tmpdir");
    writeFile(tmpdir, "t.stg", templates);
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    ST st = group.getInstanceOf("main");
    STViz viz = st.inspect();
}
 
Example #23
Source File: STViz.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void test1() throws IOException
{ // test rig
    String templates = "method(type,name,locals,args,stats) ::= <<\n"+"public <type> <name>(<args:{a| int <a>}; separator=\", \">) {\n"+"    <if(locals)>int locals[<locals>];<endif>\n"+"    <stats;separator=\"\\n\">\n"+"}\n"+">>\n"+"assign(a,b) ::= \"<a> = <b>;\"\n"+"return(x) ::= <<return <x>;>>\n"+"paren(x) ::= \"(<x>)\"\n";
    String tmpdir = System.getProperty("java.io.tmpdir");
    writeFile(tmpdir, "t.stg", templates);
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    ST st = group.getInstanceOf("method");
    st.impl.dump();
    st.add("type", "float");
    st.add("name", "foo");
    st.add("locals", 3);
    st.add("args", new String[] {"x",
                                 "y",
                                 "z"});
    ST s1 = group.getInstanceOf("assign");
    ST paren = group.getInstanceOf("paren");
    paren.add("x", "x");
    s1.add("a", paren);
    s1.add("b", "y");
    ST s2 = group.getInstanceOf("assign");
    s2.add("a", "y");
    s2.add("b", "z");
    ST s3 = group.getInstanceOf("return");
    s3.add("x", "3.14159");
    st.add("stats", s1);
    st.add("stats", s2);
    st.add("stats", s3);
    STViz viz = st.inspect();
    System.out.println(st.render()); // should not mess up ST event lists
}
 
Example #24
Source File: STViz.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void test3() throws IOException
{
    String templates = "main() ::= <<\n"+
                       "Foo: <{bar};format=\"lower\">\n" +">>\n";
    String tmpdir = System.getProperty("java.io.tmpdir");
    writeFile(tmpdir, "t.stg", templates);
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    ST st = group.getInstanceOf("main");
    st.inspect();
}
 
Example #25
Source File: STViz.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void test2() throws IOException
{ // test rig
    String templates = "t1(q1=\"Some\\nText\") ::= <<\n"+
                       "<q1>\n" +">>\n"+"\n"+"t2(p1) ::= <<\n"+
                       "<p1>\n"+
                       ">>\n"+
                       "\n"+
                       "main() ::= <<\n" +"START-<t1()>-END\n"+"\n"+"START-<t2(p1=\"Some\\nText\")>-END\n"+">>\n";
    String tmpdir = System.getProperty("java.io.tmpdir");
    writeFile(tmpdir, "t.stg", templates);
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    ST st = group.getInstanceOf("main");
    STViz viz = st.inspect();
}
 
Example #26
Source File: STViz.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void test1() throws IOException
{ // test rig
    String templates = "method(type,name,locals,args,stats) ::= <<\n"+"public <type> <name>(<args:{a| int <a>}; separator=\", \">) {\n"+"    <if(locals)>int locals[<locals>];<endif>\n"+"    <stats;separator=\"\\n\">\n"+"}\n"+">>\n"+"assign(a,b) ::= \"<a> = <b>;\"\n"+"return(x) ::= <<return <x>;>>\n"+"paren(x) ::= \"(<x>)\"\n";
    String tmpdir = System.getProperty("java.io.tmpdir");
    writeFile(tmpdir, "t.stg", templates);
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    ST st = group.getInstanceOf("method");
    st.impl.dump();
    st.add("type", "float");
    st.add("name", "foo");
    st.add("locals", 3);
    st.add("args", new String[] {"x",
                                 "y",
                                 "z"});
    ST s1 = group.getInstanceOf("assign");
    ST paren = group.getInstanceOf("paren");
    paren.add("x", "x");
    s1.add("a", paren);
    s1.add("b", "y");
    ST s2 = group.getInstanceOf("assign");
    s2.add("a", "y");
    s2.add("b", "z");
    ST s3 = group.getInstanceOf("return");
    s3.add("x", "3.14159");
    st.add("stats", s1);
    st.add("stats", s2);
    st.add("stats", s3);
    STViz viz = st.inspect();
    System.out.println(st.render()); // should not mess up ST event lists
}
 
Example #27
Source File: STViz.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void test3() throws IOException
{
    String templates = "main() ::= <<\n"+
                       "Foo: <{bar};format=\"lower\">\n" +">>\n";
    String tmpdir = System.getProperty("java.io.tmpdir");
    writeFile(tmpdir, "t.stg", templates);
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    ST st = group.getInstanceOf("main");
    st.inspect();
}
 
Example #28
Source File: STViz.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void test2() throws IOException
{ // test rig
    String templates = "t1(q1=\"Some\\nText\") ::= <<\n"+"<q1>\n"+">>\n"+"\n"+"t2(p1) ::= <<\n"+
                       "<p1>\n"+
                       ">>\n"+
                       "\n" +"main() ::= <<\n"+"START-<t1()>-END\n"+"\n"+"START-<t2(p1=\"Some\\nText\")>-END\n"+">>\n";
    String tmpdir = System.getProperty("java.io.tmpdir");
    writeFile(tmpdir, "t.stg", templates);
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    ST st = group.getInstanceOf("main");
    STViz viz = st.inspect();
}
 
Example #29
Source File: STViz.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void test1() throws IOException
{ // test rig
    String templates = "method(type,name,locals,args,stats) ::= <<\n"+"public <type> <name>(<args:{a| int <a>}; separator=\", \">) {\n"+"    <if(locals)>int locals[<locals>];<endif>\n"+"    <stats;separator=\"\\n\">\n"+"}\n"+">>\n"+"assign(a,b) ::= \"<a> = <b>;\"\n"+"return(x) ::= <<return <x>;>>\n"+"paren(x) ::= \"(<x>)\"\n";
    String tmpdir = System.getProperty("java.io.tmpdir");
    writeFile(tmpdir, "t.stg", templates);
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    ST st = group.getInstanceOf("method");
    st.impl.dump();
    st.add("type", "float");
    st.add("name", "foo");
    st.add("locals", 3);
    st.add("args", new String[] {"x",
                                 "y",
                                 "z"});
    ST s1 = group.getInstanceOf("assign");
    ST paren = group.getInstanceOf("paren");
    paren.add("x", "x");
    s1.add("a", paren);
    s1.add("b", "y");
    ST s2 = group.getInstanceOf("assign");
    s2.add("a", "y");
    s2.add("b", "z");
    ST s3 = group.getInstanceOf("return");
    s3.add("x", "3.14159");
    st.add("stats", s1);
    st.add("stats", s2);
    st.add("stats", s3);
    STViz viz = st.inspect();
    System.out.println(st.render()); // should not mess up ST event lists
}
 
Example #30
Source File: STViz.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void test3() throws IOException
{
    String templates = "main() ::= <<\n"+
                       "Foo: <{bar};format=\"lower\">\n" +">>\n";
    String tmpdir = System.getProperty("java.io.tmpdir");
    writeFile(tmpdir, "t.stg", templates);
    STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
    ST st = group.getInstanceOf("main");
    st.inspect();
}