[GOODIE] Method Annotations
Andreas Raab
andreas.raab at gmx.de
Wed Aug 20 22:52:59 UTC 2003
Oh, interesting. I wasn't aware someone else is interested in associating
meta-properties with methods. Here is my attempt on it - slightly less
verbose as it uses the <pragma: foo> syntax but slightly more restricted in
such that the annotation can only be unary (so no <key: #hello value:
#world> annotations though this would be fixable). And of course it hacks
Parser ;-)
"Change Set: MethodAnnotations-ar
Date: 2 January 2002
Author: Andreas Raab
WARNING: This CS has been manually re-arranged.
Optional annotation for methods. All <mumble> expressions are now treated as
property of the compiled method. In other words, a method may look like:
Object>>mumble
<categories: #(basic eToy)>
<index: 42>
<value: 123.45>
<returnType: Array>
After the method is compiled we may query it for those properties as in:
(Object compiledMethodAt: #mumble)
valueOfProperty: #categories; => #(basic eToy)
valueOfProperty: #index; => 42
valueOfProperty: #value; => 123.45
valueOfProperty: #returnType. => Array
"
Cheers,
- Andreas
> -----Original Message-----
> From: squeak-dev-bounces at lists.squeakfoundation.org
> [mailto:squeak-dev-bounces at lists.squeakfoundation.org] On
> Behalf Of Avi Bryant
> Sent: Thursday, August 21, 2003 12:44 AM
> To: squeak-dev at lists.squeakfoundation.org
> Subject: [GOODIE] Method Annotations
>
>
> This is an experimental goodie that allows metadata to be
> associated with
> individual methods. It's modelled loosely after VisualWorks pragma
> declarations, but doesn't (for now) modify the parser. Instead,
> annotations are added by sending #asAnnotation to an array literal
> somewhere in the body of the method.
>
> For example, you might add a method to Browser to generate instance
> variable accessors, and wish it to show up in the class list
> menu. If the
> Browser was annotation-aware, you might do this:
>
> generateAccessors
> #(menuItem: 'generate accessors' menu: #classList) asAnnotation.
> ".... the rest of the method ..."
>
> If this was part of the refactoring browser package, you
> might mark that
> with an annotation as well:
>
> generateAccessors
> #(package: 'Refactory') asAnnotation.
> #(menuItem: 'generate accessors' menu: #classList) asAnnotation.
> ".... the rest of the method ..."
>
> CompiledMethod>>annotations will return a collection of
> Message objects -
> in the above example, there would be two, with selector #package: and
> args #('Refactory'), and selector #menuItem:menu: with args
> #('generate
> accessors' #classList).
>
> Behavior>>methodAnnotations will return a collection of
> associations from
> MethodReference to Message for any annotated methods;
> #allMethodAnnotations will return the annotations for any
> superclasses as
> well.
>
> If this is at all well received, I intend to enhance
> PackageInfo to honor
> #package: annotations, and to begin to experiment with using
> annotations
> to build dynamic menus. I'm also curious how they could be used to
> provide hints for MorphicWrappers/NakedObjects-like UIs.
>
> This package is also available from
> http://beta4.com/squeak/Annotations-ab.3.mcz
>
> Comments?
>
> Avi
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MethodAnnotations-ar.cs
Type: application/octet-stream
Size: 14220 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20030821/64db008a/MethodAnnotations-ar.obj
More information about the Squeak-dev
mailing list
|