[stringtemplate-interest] v4 model adaptor unit tests

Rafael Chaves rafael at alphasimple.com
Thu Dec 23 18:18:50 PST 2010


My concrete use case: adapting UML model elements. Consider the model
class hierarchy:

NamedElement
    Class
    Feature
        Property
        Operation

- NamedElementAdaptor handles a "isPublic" property.
- FeatureAdaptor handles a "isStatic" property.
- OperationAdaptor handles a "hasParameters" property.
- PropertyAdaptor handles an "initialValue" property.

I don't want my adaptors to have to handle the case a property is
natively supported by the object itself. And I would not want to have
to handle "isPublic" in PropertyAdaptor.

I guess I work around that on my side by making PropertyAdaptor extend
FeatureAdaptor, which would extend NamedElementAdaptor, and implement
the "passing up" that way (by calling super.getProperty() instead of
failing). NamedElementAdaptor would actually extend your
ObjectModelAdaptor (which would handle the reflection case and fail
hard).

Cheers,

Rafael

On Thu, Dec 23, 2010 at 5:52 PM, Terence Parr <parrt at cs.usfca.edu> wrote:
> Well it's an error if a.prop doesn't exist I think.  being null is ok though so
>
> <if(a.children)>...<endif>
>
> works w/o throwing an exception. but if children is not a valid field or method addressed by a model, it's a programming error I think.  I'm a bit tired at moment though so I'm happy to consider some use cases if you can pass 'em along.
>
> Ter
>
> On Dec 23, 2010, at 5:45 PM, Rafael Chaves wrote:
>
>> It seems the way an adaptor passes up the opportunity to address a
>> property is by throwing an exception. Is that correct, or does the
>> exception signals a real error and aborts property resolution? It was
>> not clear from the test cases as both adaptors handle the exact same
>> properties.
>>
>> If that is correct, doesn't throwing exceptions for the majority of
>> properties being resolved (which in the normal case would be handled
>> by the default ObjectModelAdaptor) create a lot of unnecessary
>> objects?
>>
>> I handled the case of not understanding a property by returning null,
>> but that does not allow actually returning null as the intended value.
>> Could be returning some other object (a DOES_NOT_UNDERSTAND string
>> constant, for instance) instead.
>>
>> Cheers,
>>
>> Rafael
>>
>> On Thu, Dec 23, 2010 at 5:24 PM, Terence Parr <parrt at cs.usfca.edu> wrote:
>>> http://www.stringtemplate.org/depot/ST4/java/main/test/org/stringtemplate/v4/test/TestModelAdaptors.java
>>> in case you want to look.  (374 tests overall)
>>> 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