Searching the workbench
搜索工作台
In this section, you will search the workbench for Java elements.
本小节,你将在工作台中搜索Java元素。
In the Search dialog, you can perform file, text or Java searches. Java searches operate on the structure of the code. File searches operate on the files by name and/or text content. Java searches are faster, since there is an underlying indexing structure for the code structure. Text searches allow you to find matches inside comments and strings.
在搜索框中,可以搜索文件、文本和Java元素。Java元素是基于代码结构搜索的,而文件是基于文件名和文本内容搜索的,Java元素搜索更快,因为有内置代码结构的索引。文本搜索可以让你找到匹配的注释和字符串。
Performing a Java search from the workbench
搜索Java元素
In the Java perspective, click the Search (
) button in the workbench toolbar or use Search > Java... from the menu bar.
在视图中点击Search (
) 按钮,或者选择Search > Java... 菜单。
If it is not already selected, select the Java Search tab.
选择Java Search选项卡。
In the Search string field, type runTest. In the Search For area, select Method, and in the Limit To area, select References.
Verify that the Scope is set to Workspace.
在输入框Search string 中输入runTest,在Search For 区域选择Method,在Limit To区域选择References,确保Scope 选择的是Workspace。
Then click Search. While searching you may click Cancel at any time to stop the search. Partial results will be shown.
然后点击Search按钮,在搜索的过程中可以随时点击Cancel 取消,已搜索到的结果将会显示出来。
In the Java perspective, the Search view shows the search results.
在Java视图中,Search 视图显示搜索结果。
Use the Show Next Match (
) and Show Previous Match (
) buttons to navigate to each match. If the file in which the match was found is not currently open, it is opened in an editor.
使用Show Next Match (
)和Show Previous Match (
)在搜索到的结果中切换,并且文件会自动在编辑器中打开。
When you navigate to a search match using the Search view buttons, the file opens in the editor at the position of the match. Search matches are tagged with a search marker in the rulers.
当在匹配到的结果之间切换时,文件会在编辑器中打开并定位到方法引用处,编辑器左侧垂直标尺会出现搜索结果标记。
Searching from a Java view
从Java视图中搜索
Java searches can also be performed from specific views, including the Outline, Type Hierarchy view and the Package Explorer view.
可以在特定的视图中搜索Java元素,比如Outline视图、类继承视图和包管理器视图。
In the Package Explorer view, double-click junit.framework.Assert.java to open it in an editor.
在包管理器视图中,双击junit.framework.Assert.java 文件在编辑器中打开。
In the Outline view, select the fail(String) method, and from its context menu, select References > Workspace.
在Outline视图中,选择fail(String)方法,右键选择References > Workspace菜单。
Searching from an editor
在编辑器中搜索
From the Package Explorer view, open junit.framework.TestCase.java. In the editor, select the class name TestCase and from the context menu, selectReferences > Workspace.
在包管理器视图中,打开junit.framework.TestCase.java文件,在编辑器中选择类名TestCase ,右键选择References > Workspace菜单。
Continuing a search from the search view
在搜索结果中继续搜索
The Search Results view shows the results for the TestCase search. Select a search result and open the context menu. You can continue searching the selected element's references and declarations.
在搜索结果中选择一个元素右键菜单继续搜索该元素的引用和声明。
If you want to follow multiple levels of method calls, you can also use Navigate > Open Call Hierarchy.
如果你想跟踪多级别的方法调用,可以使用Navigate > Open Call Hierarchy菜单。
Performing a file search
文件搜索
In the Java perspective, click the Search button in the workbench toolbar or select Search > File from the menu bar.
在Java视图中,点击Search 按钮,或选择Search > File菜单。
If it is not already selected, select the File Search tab.
切换到File Search选项卡。
In the Containing text field, type TestCase. Make sure that the File name patterns field is set to *.java. The Scope should be set to Workspace. Then click Search.
在Containing text 输入框中输入TestCase,在File name patterns 输入框中输入*.java,Scope 设置为Workspace,然后点击Search按钮。
To find all files of a given file name pattern, leave the Containing Text field empty.
Containing Text输入框为空将搜索所有与名称匹配的文件。
Viewing previous search results
查看前一次搜索结果
In the Search Results view, click the arrow next to thePrevious Search Results toolbar button to see a menu containing the list of the most recent searches. You can choose items from this menu to view previous searches. The list can be cleared by choosing Clear History.
在搜索结果视图中,点击Previous Search Results 按钮右边的下拉方向箭头查看最近几次搜索列表,可以选择一项来查看搜索结果,该列表可以通过Clear History操作清除。
The Previous Search Results button will display a dialog with the list of all previous searches from the current session.
点击Previous Search Results按钮将会显示包含之前搜索列表的对话框。
Selecting a previous search from this dialog will let you view that search.
选择列表中的一项可以查看之前搜索的结果。