[Newbie] [RFI] For a given class how do I enumerate all the messages sent to self?

Ned Konz ned at squeakland.org
Mon Feb 21 08:21:59 UTC 2005


On Sunday 20 February 2005 1:49 am, Peace Jerome wrote:
> For a given class how do I enumerate all the messages
> sent to self?
>
> Is something I could use a clear concise answer to,
> from someone who may know exactly how to  say this to
> squeak in a way it would understand.
>
> Motives and examples are sideways to the curiosity and
> the point. Its a newbie question and I'm not ashamed
> of my stumbiling around. That's how newbies learn.

You can examine the compiled methods (decompile or parse the bytecodes) or 
parse the source.

The easiest way to do this is to use the existing parsers (the stock Squeak 
one, or (easier) the Refactoring Browser one).

The Refactoring Browser comes with Small Lint, which includes a number of 
tests for this kind of thing.

But anyway, what you'd do is search for self sends across the class, by 
examining the parse trees. The RBNode that represents a message send can tell 
you if its receiver is 'self' or 'super'.

Luckily, the RB comes with a little ready-to-run code finder tool which is 
easy to tell to find such things.

If you load the RefactoringBrowser, and then start up a Code Finder tool on a 
class (class list menu/RB-class/find code like...) and enter a pattern like:

self `@method: `@Args

and a condition like ('self searchEnvironment' is the FinderTool's currently 
searched environment):

self searchEnvironment classes noneSatisfy: [ :cls | cls canUnderstand: aNode 
selector ]

then you will find all the methods that send a message to the class that it 
doesn't understand.

You would do about the same thing for super sends, except that you would say 
'cls superclass canUnderstand:' and would use super in the pattern.

Also look at the subclasses of LintRule; these have canned search patterns.

You can also provide rewrite rules that combine the above searching with parse 
tree (hence source code) modifications.

-- 
Ned Konz
http://bike-nomad.com/squeak/



More information about the Squeak-dev mailing list