[stringtemplate-interest] StringTemplate type proxies
Sam Harwell
sharwell at pixelminegames.com
Tue Dec 14 13:18:45 PST 2010
Using a single instance doesn't make nearly as much sense for .NET as it
does for Java. Most attributes we use are properties, which don't take any
arguments, and the only way to preserve this is using a factory which wraps
instances. Also, wrapper creation overhead [should be] trivial compared to
the parsing and string manipulation functions in ST. I'll run the result
through a profiler soon to confirm this.
Sam
-----Original Message-----
From: stringtemplate-interest-bounces at antlr.org
[mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Terence Parr
Sent: Tuesday, December 14, 2010 2:06 PM
To: Rafael Chaves
Cc: stringtemplate-interest at antlr.org
Subject: Re: [stringtemplate-interest] StringTemplate type proxies
Ah! You are so correct! It only works on the values you pass through
setAttribute. Ok, so the proposition is to simply add
registerProxy(ModelType, MyProxyType)
and have ST created new MyProxyType object with
new MyProxyType(aModelTypeObjectAttribute)
for each reference to a ModelType object? Won't that get inefficient?
perhaps it should be like renderer and we create a single object to wrap
any object?
$a.foo$ would invoke method MyProxyType.getFoo(a), right?
Am I going in the right direction?
Ter
On Dec 14, 2010, at 11:28 AM, Rafael Chaves wrote:
> Yup, renderers translate from whatever values to String. The decorator
> (not a proxy, as it augments the shape of the target object) allows
> obtaining the values.
>
> This should apply at any level in the model graph, not only top level
> attributes. Does setAttribute handle that?
>
> For instance: Package has Classes with have Attributes. I set only one
> attribute on the top-level template, to be the root package object,
> and then navigate the graph with several templates (one for packages,
> one for classes, and another for attributes).
>
> Will overriding setAttribute allow me to intercept how any arbitrarily
> deep object is handled?
>
> Cheers,
>
> Rafael
>
> On Tue, Dec 14, 2010 at 11:16 AM, Terence Parr <parrt at cs.usfca.edu> wrote:
>> Very convincing argument, folks. thank you. 3rd party models.
>>
>> Ok, so how do they interact with renderers? I guess the renderer is done
*after* proxy stuff.
>>
>> Proxy: RandomModelObject -> MyWrapperForRandomModelObject, adds getFoo()
or whatever.
>>
>> Then, if getFoo() returns type Date, renderer applies to that. I like
it.
>>
>> I remember mentioning how to do this manually. just override
setAttribute() so that it traps RandomModelObject and wraps.
>>
>> Does this need to be formalized or can it simply be a FAQ entry? it's a
switch on type, look up in hashtable thing only right?
>>
>> Ter
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
_______________________________________________
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