Code Search Patterns

Help Index


Introduction

The code searcher allows for more complex searches compared to simple string or pattern searches - it allows you to enter a smalltalk code fragment and search on the code-tree level (i.e. smalltalk-syntax aware searching).

For example, you can search for assignments of the value 1234 to a variable named myVar with:

    myVar := 1234
This will find the assignments even if the code is formatted with whiteSpaceor comments or both.

Meta Characters/Variables

Each meta-variable must begin with a ` (backquote) character. Immediately following the ` character, other character can be entered to specify what type of node this meta-variable can match. After all the special character have been entered, you must then enter a valid variable name.
The special characters currently supported are listed in the following table:
@ - list
When applied to a variable node, this will match a literal, variable, or a sequence of messages sent to a literal or variable

When applied to a keyword in a message, it will match a list of keyword messages (i.e., any message send)

When applied with a statement character, it will match a list of statements

For example:

    | `@Temps | 
matches list of temps

    `@.Statements
matches list of statements

    `@object
matches any message node, literal node or block node

    foo `@message: `@args
matches any message sent to foo.

. - statement
matches a statement in a sequence node

For example:

    `.Statement
matches a single statement

# - literal
matches only literal objects

For example:

    `#literal
matches any literal (#(), #foo, 1, etc.)

` (backquote) - recurse into
Whenever a match is found, look inside this matched node for more matches.
For example:
    `@object foo
matches a foo message sent to any expression on the outer level. However, the code "self foo foo" will be matched only once.

In contrast,

    ``@object foo
also matches foo sent to any object, plus for each match found, it will look for more matches in the ``@object part. Thus, this will match twice for the "self foo foo" example.

Examples

Search for at:put: being sent to the Smalltalk-global, with a variables value as argument, use
    Smalltalk at:`key put:`val
the above does not match for literal values or expression values as argument(s).
To match those, use
    Smalltalk at:`@key put:`@val
to even look into the argument and look for sends there too, use:
    Smalltalk at:``@key put:``@val
To search for any message send:
    ``@rec `@msg: ``@args
To search for exception handlers:
    ``@rec on: ``@arg1 do: ``@arg2
and:
    ``@rec handle: ``@arg1 do: ``@arg2
or, for a particular class:
    StreamError handle: ``@arg1 do: ``@arg2

Copyright © Claus Gittinger Development & Consulting, all rights reserved


Doc $Revision: 1.2 $ $Date: 2003/10/06 11:11:59 $