[stringtemplate-interest] Conditionally included subtemplates?
Terence Parr
parrt at cs.usfca.edu
Thu Feb 10 15:51:22 PST 2011
Yeah, it throws an exception for missing properties. a quirky thing but my view of the past was that a missing method or field was a programming error; in ST v4 coming soon to a theater near you, this does not generate an exception
Ter
On Feb 5, 2011, at 10:26 PM, erwin.mueller at deventm.org wrote:
> Hello,
>
> I'm a new user of StringTemplate and so far I have manage my simple
> templates w/o any problems. But I wonder in a template like [1] I understood the
> documentation that the subtemplate will be included if the attribute ``address''
> exists. Why do I get then NoSuchFieldException [2]? My classes are like in [3]
> where ``httpd'' is an object of classes implementing the ``HttpdDirective''
> interface.
>
> I understood the documentation ``IF actions test the presence or absence of
> an attribute unless the object is a Boolean/bool, true".
> For example,"$if(!member)$...$endif$".'' Presence or absence is for me whether
> the object have the attribute or not. What is the documentation understands as
> ``presence'' or ``absence''?
>
> Kind regards, Erwin.
>
> [1]
> domains(httpd) ::= <<
> \<!-- domains --\>
> <httpd.directives:{<if(it.address)>{NameVirtualHost <it.address><\n>}<endif>}>
>>>
>
> [2]
> Class
> com.globalscalingsoftware.sscontrol.cli.internal.application.services.httpd.
> directives.SetupJkWorkerDirective$$EnhancerByGuice$$f9c51395 has no such
> attribute: address in template context [httpd_default domains anonymous]
> java.lang.NoSuchFieldException: address
>
> [3]
> public interface HttpdDirective {
>
> String getTemplateName();
>
> HttpdDirective setProperty(String name, Object value);
>
> }
>
> public class DomainDirective implements HttpdDirective {
>
> public String getAddress() {
> return address;
> }
>
> }
>
> public class SetupJkWorkerDirective implements HttpdDirective {
> // no getAddress() method
> }
> --
> Erwin Mueller, erwin.mueller at deventm.org
> http://www.global-scaling-institute.de/
> http://www.deventm.org
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list