agam
agam

Reputation: 5394

How do I lookup which class implements a method in Pharo?

Newbie here, going through "Pharo by Example". The book mentions an example of EllipseMorph new openInWorld result in a call to Morph openInWorld, while EllipseMorph defaultColor is an overridden message: how do I figure this out using the System Browser or something else?

The usual find method way only finds matches in the immediately selected class. Is it possible in general to lookup which class will respond to (say) Foo bar?

Update: Thanks for all the suggestions (Finder, Spotter); the Debugger is the most eye-opening of the tools I've encountered yet!

Upvotes: 4

Views: 786

Answers (2)

Stephan Eggermont
Stephan Eggermont

Reputation: 15917

Smalltalk offers lots of tools and browsers that can help you with this. If you already know the name of the message, you can:

  • use spotter (Shift+Enter) to type it in and see all senders and implementers, and select one to browse it.
  • while looking at a method in a browser, click on the small green up/down triangles to the left of the method name indicating implementations up and/or down the hierarchy, respectively, to open a browser on them.
  • select the name of the message (nearly) anywhere and type CMD+M to see the implementors and CMD+N to see the senders.

In this case you could also type EllipseMorph new openInWorld in a playground and select Debug-It from the menu. That will open a debugger with the selection on new. If you click on into, the top line changes to EllipseMorph class(Behavior) new. That indicates that the new from Behavior is used here. If you continue stepping with into (2 times), you'll see it change to EllipseMorph(BorderedMorph) initialize. By just following the trace of messages sent, you can see where everything is implemented.

Upvotes: 5

Amos M. Carpenter
Amos M. Carpenter

Reputation: 4958

To add to Stephan's answer (+1), one of the easiest ways, especially if you're new to Smalltalk and prefer using the GUI, is to use the Finder tool. Just left-click anywhere on the background (the equivalent of your desktop in your Pharo image) and select Tools > Finder:

Opening the Finder tool in Pharo

Next, type the name of the method, e.g. openInWorld in the search field (make sure "Selectors" is selected in the drop-down to the right) and hit Enter:

Using the Finder tool in Pharo

You can then browse all methods containing your search string (notice it's automatically a wildcard search) and the classes implementing them. The panel at the bottom shows you selected implementations, and the context menu gives you a few more options, e.g. browsing the class you selected.

Upvotes: 5

Related Questions