[stringtemplate-interest] Primitives and Model Adapters

Terence Parr parrt at cs.usfca.edu
Thu Jan 27 16:37:08 PST 2011


Actually, can't make it work. register with Integer.class :)  everything is object inside interp.

Ter
On Jan 27, 2011, at 3:58 PM, Collin Fagan wrote:

> Hi,
>      Should one be able to register a model adapter for a primitive type? I can't seem to get this to work. One added complexity is that you cannot pass a primitive to add because it gets auto-boxed to it's object type.
> 
> Here is some code to reproduce this. 
> 
> Thanks, Collin
> 
>     @Test
>     public void testPrimitiveMA() {
>         STGroup group = new STGroup();
>         group.registerModelAdaptor(boolean.class, testModelAdaptor);
>         group.defineTemplate("main", "example", "<example.boolean.callMA>");
>         ST mainTemplate = group.getInstanceOf("main");
> 
>         mainTemplate.add("example", new Example());
>         assertEquals("Model Adapter Called", mainTemplate.render());
>     }
> 
>     private ModelAdaptor testModelAdaptor = new ModelAdaptor() {
> 
>         @Override
>         public Object getProperty(ST self, Object o, Object property, String propertyName) throws STNoSuchPropertyException {
>             return "Model Adapter Called";
>         }
>     };
> 
>     private class Example {
>         public boolean getBoolean() {
>             return true;
>         }
>     }
> 
> _______________________________________________
> 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