Some Essential Skills

There are some additional skills that are good to know about. For example, if you highlight an item in the JDT editor, right-click it, and select Open Declaration, the declaration of that item will open. This is great for tracking down where and how methods and fields were created. Several of those are detailed in this section and all are worth adding to your Eclipse toolbox.

Viewing Type Hierarchies

Another menu item in the JDT editor's context menu is the Open Type Hierarchy; when you select an item in the editor and select this menu item, that item's type hierarchy appears in the Java perspective's hierarchy view, as you see at left in Screenshot-24.

Screenshot-24. The hierarchy view
Java figs/ecps_0224.gif

This view acts like an object browser. It lets you explore a type's Java complete hierarchy, and double-clicking an item in this view opens its definition in the editor. That's useful if, for example, you want to see all the members of the System.out class—just highlight System.out in your code and open its hierarchy. You can also open this view by selecting an item in the editor and selecting the NavigateScreenshot Open Type Hierarchy item. The hierarchy view is not dissimilar from the outline view, which you see at right in Screenshot-24. However, the outline view is designed to show an automatic hierarchy of your code rather than the hierarchy of items you specifically select. As you work in the JDT editor, the outline view is updated automatically to show the hierarchy of the current type you're working with.

Browsing Java Code

There's even another entire perspective dedicated to letting you browse through projects in a Java-oriented way: the Java Browsing perspective. To open this perspective, select WindowScreenshot Open PerspectiveScreenshot Java Browsing; you can see the results in Screenshot-25.

Screenshot-25. The Java browsing perspective
Java figs/ecps_0225.gif

This perspective presents the information you see in the standard Java perspective in a new way, and it breaks type and member information into two new views (the Members view here is much like the Outline view in the standard Java perspective). As you'd expect, the views in this perspective are all coordinated—selecting an element in the Projects views makes its packages appear in the Packages view, for example. And selecting an item in the Members view makes that item appear in the editor, and so on.

Searching Code

Eclipse also has great facilities for searching through code in the Search menu. In fact, the main menu items in the Search menu, SearchScreenshot Search, SearchScreenshot File, SearchScreenshot Help, and SearchScreenshot Java, all open the Search dialog, although each item corresponds to a different tab in that dialog. Searching is particularly powerful in Eclipse—for example, not only can you search across multiple files, you can also search using wildcards. The File Search tab in the Search dialog lets you search across multiple files. For example, in Screenshot-26, we're searching for the word main through all .java files in the workspace. The scope of the search is set with the radio buttons in the Scope box, and the default is to search all matching files throughout the workspace (that is, all your projects that appear in the Package Explorer). You can also restrict the search to a working set (covered in a few pages) of projects. If you want to search only the current project or just a restricted number of projects, you can select that project or those projects in the Package Explorer, then open the Search dialog and select the Selected Resources radio button in the Scope box.

Screenshot-26. Performing a file search
Java figs/ecps_0226.gif

Clicking Search makes Eclipse search for matches to the text you've entered, and you can see the results in the Search Results view, which appears at the bottom in Screenshot-27. Double-clicking a match in the Search Results view opens the match in the JDT editor, as you can see in the figure, and both underlines the match and points to it with an arrow.

Screenshot-27. Viewing search results
Java figs/ecps_0227.gif

You can also perform Java searches with the Java tab in the Search dialog. This lets you search for Java elements by kind—types, methods, packages, constructors, and fields—as you can see in Screenshot-28. You can also limit the search so that it only matches declarations or references.

Screenshot-28. Performing a Java search
Java figs/ecps_0228.gif

Being able to search across files and classes is one of the big advantages of using an IDE—if you've been doing Java development using a text editor and javac, you'll find there's no comparison when you start using the project management capabilities like these in Eclipse.

      
Comments