Skip to main content
Engineering LibreTexts

2.11: Finding Classes

  • Page ID
    39738
    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    There are several ways to find a class in Pharo. The first, as we have just seen above, is to know (or guess) what package it is in, and to navigate to it using the browser.

    A second way is to send the browse message to the class, asking it to open a browser on itself. Suppose we want to browse the class Point.

    Using the message browse

    Type Point browse into a playground and Do it. A browser will open on the Point class.

    Using CMD-b to browse

    There is also a keyboard shortcut CMD-b (browse) that you can use in any text pane; select the word and press CMD-b. Use this keyboard shortcut to browse the class Point.

    Notice that when the Point class is selected but no protocol or method is selected, instead of the source code of a method, we see a class definition. This is nothing more than an ordinary message that is sent to the parent class, asking it to create a subclass. Here we see that the class Object is being asked to create a subclass named Point with two instance variables, class variables, and to put the class Point in the Kernel-BasicObjects package. If you click on the Comments button at the bottom of the class pane, you can see the class comment in a dedicated pane.

    In addition the system supports the following mouse shortcuts

    • CMD-Click on a word: open the definition of a class when the word is a class name. You get also the implementers of the message when you click on a selector that is in the body of a method.
    • CMD-Shift-Click on a word: open a list browser with all the refs of the class when the word is a class name. You get also the senders of the message when you click on a selector that is in the body of a method.

    Using Spotter

    The fastest (and probably the coolest) way to find a class is to use Spotter. Pressing Shift+Enter opens Spotter, a very powerful tool for finding classes, methods, and many other related actions. Figure \(\PageIndex{1}\) shows that we look for Point.

    Opening Spotter.
    Figure \(\PageIndex{1}\): Opening Spotter.

    Spotter offers several possibilities as shown in Figure \(\PageIndex{1}\). You can specify to Spotter the kind of categories you are interested in. For example, using #class followed by the word you look for, indicates that you are interested in classes. This is the default so you do not need to type #class.

    Figure \(\PageIndex{2}\) shows how we can ask Spotter to show all the implementors of a given messages. We do not have to type the full category name. Other Categories are menu, packages, method (#implementor), examples (#example), pragma (#pragma), senders (#sender), class references (#reference) but also playground code snippets (using #playground).You can just type the beginning of the category to identify it i.e., #ref Point will give all the reference to the class Point.

    Implementors matching printString.
    Figure \(\PageIndex{2}\): Looking for implementors matching printString.

    Spotter can be used even to browse through the OS file system, and has a history category where previous searches are stored for quickly going back to popular searches.

    Navigating results

    In addition we can use Spotter to navigate to our search results similarly to how we use System Browser. Spotter categorizes its search results: for example, classes are under Classes category, methods under the Implementors category, help topics under Help Topics category, etc.

    Clicking on the right arrow will take us to our selection and create a tab on top that we can click to go back to where we were. Depending on what we click on, we step into our selection and are exposed to more categories.

    For example, if our selection is the Point class, we will dive inside a group of categories made for instance methods, class methods, super instance methods etc.

    The interface is fully controllable through the keyboard. The user can move with Up/Down arrows between items or Cmd-Shift-Up/Cmd-Shift-Down arrows (note that on Windows and Linux Cmd key is the Alt key) through categories. At the same time, the search field has the focus, so the user can switch seamlessly between selecting items and refining the search. Pressing Enter on a selection opens the System Browser on that specific selected search result.

    Using ’Find class’ in System Browser

    In the SystemBrowser you can also search for a class via its name. For example, suppose that you are looking for some unknown class that represents dates and times.

    In the System Browser, click anywhere in the package pane or the class pane, and launch the Class Search window by typing CMD-f CMD-c, or selecting Find class (f,c) from the right-click context menu. Type time in the dialog box and click OK (or press Enter).

    A list of classes is displayed, whose names contain the substring time. Choose one (say, Time), and the browser will show it, along with a class comment that suggests other classes that might be useful. If you want to browse one of the others, select its name (in any text pane), and type CMD-b.

    Note that if you type the complete (and correctly capitalized) name of a class in the find dialog, the browser will go directly to that class without showing you the list of options.

    Using the Finder

    You can also open the Finder that is available from the World > Tools... menu, and type part of the name of the class and change the Selectors to Classes in the right combo box. It is less efficient than using Spotter or the SystemBrowser as explained above. The Finder is more useful for other types of code searches such as find methods based on examples, as we will show later.


    This page titled 2.11: Finding Classes is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.