[stringtemplate-interest] Variables in Template Parameters

Brain, Jim JBrain at Aegonusa.com
Mon Nov 9 15:07:53 PST 2009


I got it to work by adding a 'builder' template as an intermediate.

import org.antlr.stringtemplate.*;
public class STTest {
	public static void main(String[] args) {
		StringTemplateGroup stg = new StringTemplateGroup("Source");
		stg.defineTemplate("reader","$type$.$getter$");
		StringTemplate st = stg.defineTemplate("prop","$reader(getter=builder())$");
		stg.defineTemplate("builder","get$name$()");
		st.setAttribute("name","Name");
		st.setAttribute("type","TYPE");
		System.out.println(st.toString());
	}
}

But, at that point, I can just do:

import org.antlr.stringtemplate.*;
public class STTest {
	public static void main(String[] args) {
		StringTemplateGroup stg = new StringTemplateGroup("Source");
		stg.defineTemplate("reader","$type$.$builder()$");
		StringTemplate st = stg.defineTemplate("prop","$reader()$");
		stg.defineTemplate("builder","get$name$()");
		st.setAttribute("name","Name");
		st.setAttribute("type","TYPE");
		System.out.println(st.toString());
	}
}

But, I prefer to not create the additional template if I can avoid it.  With the number of templates in use now, I'm already having to increase heap size.

Jim



More information about the stringtemplate-interest mailing list