Skip to main content
Engineering LibreTexts

16.5: Browsing Environments

  • Page ID
    39671
    \( \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}}\)

    Although SystemNavigation offers some useful ways to programmatically query and browse system code, there are more ways. The Browser, which is integrated into Pharo, allows us to restrict the environment in which a search is to perform.

    Suppose we are interested to discover which classes refer to the class Point but only in its own package.

    Open a browser on the class Point.

    Action-click on the top level package Kernel in the package pane and select Browse scoped. A new browser opens, showing only the package Kernel and all classes within this package (and some classes which have extension methods from this package). Now, in this browser, select again the class Point, Action-click on the class name and select Analyse > Class refs. This will show all methods that have references to the class Point but only those from the package Kernel. Compare this result with the search from a Browser without restricted scope.

    This scope is what we call a Browsing Environment (class RBBrowserEnvironment). All other searches, like senders of a method or implementors of a method from within this browser are restricted to this environments too.

    Browser environments can also be created programmatically. Here, for example, we create a new RBBrowserEnvironment for Collection and its subclasses, select the super-sending methods, and browse the resulting environment.

    ((RBBrowserEnvironment new forClasses: (Collection withAllSubclasses))
        selectMethods: [:method | method sendsToSuper])
        browse.
    

    Note how this is considerably more compact than the earlier, equivalent example using SystemNavigation.

    Finally, we can find just those methods that send a different super message programmatically as follows:

    ((RBBrowserEnvironment new forClasses: (Collection withAllSubclasses))
        selectMethods: [:method |
            method sendsToSuper
            and: [(method parseTree superMessages includes: method selector)
                not]])
        browse
    

    Here we ask each compiled method for its (Refactoring Browser) parse tree, in order to find out whether the super messages differ from the method’s selector. Have a look at the querying protocol of the class RBProgramNode to see some the things we can ask of parse trees.

    Instead of browsing the environment in a System Browser, we can spawn a MessageBrower from the list of all methods in this environment.

    MessageBrowser browse: ((RBBrowserEnvironment new forClasses:
            (Collection withAllSubclasses))
        selectMethods: [:method |
            method sendsToSuper
            and: [(method parseTree superMessages includes: method selector)
                not]]) methods
        title: 'Collection methods sending different super'
    

    In Figure \(\PageIndex{1}\) we can see that 5 such methods have been found within the Collection hierarchy, including Collection>>printNameOn:, which sends super printOn:.

    Finding methods.
    Figure \(\PageIndex{1}\): Finding methods.

    This page titled 16.5: Browsing Environments 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.