Now that you've had the birds-eye view of BBQ, you may be looking for examples that illustrate how the pieces fit together. We'll examine in detail some queries that perform tasks which I hope are both recognizable as the sort of tasks you might face, and also complex enough to show how the power of BBQ can be useful.
To warm up, we'll write some queries that perform basic browsing functionality that is already available in most IDE's. If you're familiar at all with your IDE, it's probably easier just to click on an object in the explorer and select the right menu item than to type in these queries, but they will illustrate the principles of BBQ, and you always have the ability to build on them to meet your specialized needs.
First, let's find the set of all calls to a particular method.
In this example we'll find the calls to the
You start with the
transform; that returns the result you want.
applies to a set of methods; so you next want to specify the method.
In BBQ you normally pick a specific method (or field) by applying the
matching filter with the name of the method to
the set of methods in a class. You pick a particular class with the
class simple set expression.
So the complete query is:
calls to matching "iterator" methods in class "java.util.ArrayList"
Finding references to fields is very similar:
references to matching "gridx" fields in class "java.awt.GridBagConstraints"
If you don't want to type the complete path of the class, you can use the
import expression to set
packages to search automatically.
Then you can write the same query:
references to matching "gridx" fields in class "GridBagConstraints"
In the examples so far, we've been querying the simple set expression
This is probably the one you will use most often, since it quickly sets the scope of the search to be
a particular class.
You can also do a more comprehensive search against
or within a
For example, to find all the classes with "List" in their name in "java.util", you would use:
matching "List" classes in package "java.util"
You can use
all packages when you
want to search through the entire analyzed system, but your query will take a little longer (or a lot longer)
to run. In some cases, this might be exactly what you need: suppose you remember
part of a method name, but can't remember what class it's in. BBQ let's you
do the search more conveniently than a string-matching search through your source
files, because BBQ knows what a method name is.
matching "scape" methods in all classes
Similarly, BBQ knows when a sequence of characters in your code is part of a string constant; there are a couple of simple set expressions just for searching string constants. You can look for references to a particular string:
references to string "import"
You can also look for all string constants in the analyzed system that contain a certain sub-string:
references to matching "import" all strings
When you look for "all references to" something in any code browser,
you will often get a lot of irrelevant results.
You'll then look through the returned items one by one to find those you are actually
If you have a good idea of the filtering you will do when you look through the browser results,
why not make this part of the query and have the browser do the work?
With BBQ you can do this; you can use set operators or the
filter to search for calls to method
only from methods that also contain calls to method
( methods containing calls to matching "foo" methods in class "Sample" ) intersection ( methods containing calls to matching "bar" methods in class "Sample" )
You now have some experience with the simple set expressions and a few of the transforms, and you can compose searches of the BBQ database equivalent to, and beyond, the browser functions of your IDE. These searches can serve as the foundation for the more sophisticated queries where BBQ really shines.
|browse-by-query home||antlersoft free software||sourceforge project page|