Finding Class, Method, and Field Usages
See Also
You can use the Find Usages command to determine everywhere a class,
method, or field is used in your project's source code.
To find where a class, interface, method, or field is used in your project:
- In the Projects window or the Source Editor window, right-click the code element
and choose Find Usages (Alt-F7).
- In the Find Usages dialog box, select options for the scope of the
search.
See the following sections of this topic for more information on the Find Usages command and its options.
- Click Next.
The Usages window
displays the file name and the line of code for each usage found in that file.
To jump to a specific occurrence of the code element, do one of the following actions:
- Double-click a file name in the Usages window to open the file.
- Double-click a line of code to open the file and to position the cursor
on that line of code.
Classes and Interfaces
For classes and interfaces, the Find Usages command displays all the code
lines that:
- Use the type, such as creating a new instance, importing, extending, implementing,
casting, or throwing
- Use the type's members and static variables
After you choose the Find Usages command on a class or interface, the Find Usages dialog box might
give you additional options:
- Find All Subtypes checkbox. If selected, only usages of subtypes of the class are displayed.
- Find Direct Subtypes Only checkbox. If selected, only usages of direct subtypes
are displayed. Subtypes of those subtypes are ignored.
Methods
For methods, the Find Usages command displays
the code lines that:
- call the method
- override the method
After you choose the Find Usages command on a method, the Find Usages dialog box might
give you additional options:
- Find Overriding Methods checkbox. If selected, any occurrences of methods that override
the selected method will be displayed.
- Search from Base Class checkbox. If selected, the output
shows every usage of that base method. This option only appears if the method
that you are finding usages for overrides another method.
Fields
For fields, the Find Usages command displays
all the code lines that:
- set the field to a value
- get the value of the field
Additional IDE Find Mechanisms
The other IDE tools that enable you to search for all
the places where specific text is used in a project include:
- Finding and Replacing Text.
Searches for all the places where specific text is
used in a source file that is open in the Java Editor. Choose Edit > Find
to open the Find dialog box, or choose Edit > Replace to open the Replace dialog box.
These commands finds all matching strings, regardless
of whether the string is a Java element.
- Find in Projects. As with the Find command,
the Find in Projects command searches for matching strings, regardless
of whether the string is a class name.
Choose Edit > Find
in Projects to open the Find in Projects dialog box and then type the string
of text that you are looking for.
- To find where a method is declared in a source file, you can either
double-click the method in the Projects window or Navigator window.
If the method is declared in a different source file, right-click the method
and choose Go To > Declaration
from the contextual menu.
- See Also
- Refactoring: Quick Reference
- Renaming a Class or Interface
- Renaming a Field or Method
- Safely Deleting Java Code
- Undoing Refactoring Changes
Legal Notices