[stringtemplate-interest] StringTemplate + Doclet
Udo Borkowski
ub at abego-software.de
Wed Dec 22 12:15:57 PST 2010
I used a different approach to make the "property access" more flexible: instead of defining/registering a class specific "adaptor" I defined an interface PropertyAccessor:
public interface PropertyAccessor {
Object getProperty(Object o, Object property, ST template,
Interpreter interpreter);
}
The Interpreter method getObjectProperty now looks like
protected Object getObjectProperty(ST self, Object o, Object property) {
return group.getPropertyAccessor().getProperty(o, property, self, this);
}
The STGroup got a new property propertyAccessor that by default references an implementation of the PropertyAccessor interface mimiking the old behaviour (i.e. getProperty(…) contains just the old code of Interpreter#getObjectProperty(…)).
Because the propertyAccessor of STGroup has also a setter I can redefine this "property access" behaviour on a per STGroup base. In this implementation I can decide if I want to use the "exact class" or "instanceOf" functionality etc.
BTW: My current implementation of the PropertyAccessor interface also contains a cache for fast access to a property. I.e. it is no longer necessary to check on every property access if the property is implemented by a "getFoo()" or "isFoo()" method or a field "foo" but I can directly use the Method or Field instance retrieved the first time. The cache maps a property name and a class to the code doing the actual property access. Subclasses/interfaces are also covered this way.
BTW2: The cache is also used to redefine property behaviour on a "per class, per propertyName" base.
Udo
On 22.12.2010, at 18:51, Terence Parr wrote:
>
> On Dec 22, 2010, at 9:38 AM, Brian Clapper wrote:
>>> contract), I ended up using ASM to generate interfaces on the fly, which I then
>> implement via java.lang.reflect.Proxy.
>
> BTW, for renderers i did == on obj.getClass() not instanceof (which only works on class names not Class ptrs). Is it a serious problem if i don't allow instanceof? Maybe if the model object is hidden by interfaces like jdbc. hmm... i'd rather avoid the java.lang.reflect.Proxy stuff.
>
> Ter
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20101222/a59cf13e/attachment.html
More information about the stringtemplate-interest
mailing list