[stringtemplate-interest] Primitives and Model Adapters

Collin Fagan collin.fagan at gmail.com
Thu Jan 27 15:58:59 PST 2011


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;
        }
    }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110127/6c668969/attachment-0001.html 


More information about the stringtemplate-interest mailing list