In addition to the navigation tools available from the Navigate menu, Eclipse includes a number of powerful search tools accessible from the Search menu. The Eclipse Search dialog, accessible via the Search > Search... command (Ctrl+H) or the Search toolbar button, acts as a portal to a number of different searching tools, including File Search, Java Search, and Plug-in Search. The two most important tools are File Search and Java Search.
1.6.1. File Search
The File Search tab (see Figure 1-28) of the Search dialog provides a way to find arbitrary files in the workbench by name or by the text they contain. To search for files containing a certain expression, enter that expression into the Containing text field. Various wildcards, such as "*" to match any set of characters and "?" to match any single character, are supported. By default, the search is case-sensitive; to make it case-insensitive, uncheck the Case sensitive option. To perform complex text searches using regular expressions, turn on the Regular expression option.
Figure 1-28. File Search tab.
To search for files by name, leave the Containing text field blank. To restrict a search to certain types of files or files containing a certain naming pattern, enter the file name expression into the File name patterns field.
The Scope fields provide another way to further restrict a search. The Workspace scope encompasses the entire workspace while the Working set scope limits a search to only those files contained in the selected working set. The Selected resources scope limits a search to only those files that have been selected in the active view (for example, the Navigator view or Package Explorer view), while the Enclosing projects scope limits a search to the projects containing the selected files.
For example, to search for all files containing the text "xml", enter that text into the Containing text field and leave the File name patterns field and Scope fields unchanged. When ready, click the Search button to find the matching files and display them in the Search view (see Figure 1-29). Clicking the Replace button rather than the Search button will perform the same search, but it will open up a Replace dialog where you can enter replacement text.
Figure 1-29. File search results.
If your goal is to search for various Java elements, such as types, methods, fields, and so on, the Java Search option is much more powerful than the File Search option.
The Java Search tab (see Figure 1-30) locates Java elements such as types, methods, constructors, fields, and packages. You can use it to find declarations of a specific Java element, references to the element, or implementors of the element (in the case of a Java interface).
Figure 1-30. Java Search tab.
To search for elements with a specific name, enter the name in the Search string field (wildcards are supported). Depending on the kind of Java element you are interested in, select the Type, Method, Package, Constructor, or Field radio button. You can further limit search results to Declarations, References, Implementors (of Java interfaces), All Occurrences, Read Access (for fields), or Write Access (for fields).
As with the File Search tab, the Scope fields provide another way to restrict a search. The Workspace scope includes the entire workspace, the Working set scope limits the search to a specific working set, the Selected resources scope limits the search to the selected files in the active view, and the Enclosing projects scope limits the search to the projects containing the selected files.
For example, to search for all methods named "toLowerCase", enter that text into the Search string field, select the Search For > Method and Limit To > Declarations radio buttons, and leave the Scope fields unchanged. When ready, click the Search button to find the methods matching that name and to display them hierarchically in the Search view. Several options are available on the view toolbar for grouping the results by project, package, file, or class. Select the Flat Layout command from the view menu to see the results listed individually (see Figure 1-31).
Figure 1-31. Java search results.
Double-clicking on any search result opens an editor on the file containing that result, highlights the search match in the text, and places a search marker in the left gutter area (also known as the marker bar, or left vertical ruler) of the editor (see Figure 1-32). Clicking the Show Next Match or Show Previous Match buttons (the up and down arrows) in the Search view selects the next or previous match (opening a new editor on a different file if necessary). You can also continue to search ("drill-down") using the context menus in the Search view.
Figure 1-32. Editor showing search match and search marker.
1.6.3. Other Search menu options
The Search menu contains a number of dedicated, easy-to-use Java search commands that replicate the options found on the Java Search page of the Search dialog (see Figure 1.33).
Figure 1-33. Dedicated Java search commands.
Selecting a Java element either in a view or in a Java editor and then selecting the Search > Declarations command finds all elements with matching declarations in the workspace, the current project, the current type hierarchy, or a specific working set. Likewise, selecting the Search > References command finds all the places where the element is used. The Search > Implementors, Search > Declarations, and Search > Write Access commands work similarly. Note that the same commands are also available from the context menu in the Java editor and the Search view.
Working sets have been mentioned a number of times so far. They are used to create a group of elements to act either as a filter in various views, such as Navigator and Package Explorer, or as search scopes in the Search dialog or any search menu. Working sets are extremely useful when you have a large workspace containing many projects because they limit the scope of your code and make many tasks easier.
To select a working set or to create a new one, choose Scope > Working Set in the Search dialog, then click the Choose button. This opens the Select Working Set dialog (see Figure 1-34). To use an existing working set, select it from the list and click the OK button. To edit a working set, click the Edit button instead.
Figure 1-34. Select Working Set dialog.
The Eclipse 3.1 version is shown on the left, and the Eclipse 3.2 version is shown on the right. Under Eclipse 3.2, multiple working sets can be selected.
Eclipse 3.2 adds the ability to select multiple working sets. This creates, in effect, a new virtual working set that merges the results from each of the selected sets. This makes it easier to create multiple, finer-grained working sets and then combine them in different combinations.
Click the New... button to create a new working set. This opens the New Working Set dialog (see Figure 1-35). Four different types of working sets can be created: Resource, Java, Plug-ins, and Breakpoint working sets. Select the type of working set you want to create and click the Next button.
Figure 1-35. New Working Set dialog.
The next page of the New Working Set dialog facilitates defining new working sets (see Figure 1-36). Enter the desired name into the Working set name field and select the contents from the Working set content list. Clicking the Finish button closes the New Working Set dialog and adds the new working set to the Select Working Set dialog.
Figure 1-36. Define a New Working Set.