Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

A simple java program to use this script would look as follows:

No Format
 importimport java.io.File;

import java.io.FileReader;



import org.antlr.stringtemplate.StringTemplate;

import org.antlr.stringtemplate.StringTemplateGroup;

import org.antlr.stringtemplate.language.DefaultTemplateLexer;



public class t {
       /* Quick and very nasty example: */
       public static void main(String[] args)
          throws Exception
       {
              File templateFileName = new File("te.stg");
              StringTemplateGroup group = new StringTemplateGroup(
                               new FileReader(templateFileName),
                            DefaultTemplateLexer.class    // Leave away if you want to use angle brace notation
                     );

                    StringTemplate template = group.getInstanceOf("variable");   

                 template.setAttribute("type", "Integer");
              template.setAttribute("name", "id");

              System.out.println(template.toString());
       }

}