Eclipse search Tips

Want to have everything at your fingertips with Eclipse ? this tutorial provides some handy tips to search and find what you are looking for in Eclipse.


How to search in a specific Eclipse project

If you have lots of open projects in your workspace then you would like to search in a specific project.
Solution: Create a working set . Working sets group elements for display in views or for operations on a set of elements.

Open the Search Menu and click on the "Choose" button to create a new Working Set:

 eclipse search1

 Next, choose New to create a new Working Set :

eclipse tips tricks tutorials

In the next screen, select "Resource":

eclipse tips tricks tutorials

Pickup one or more projects from your Workspace which will be part of your Working Set:

eclipse tips tricks tutorials

Now you can use the New Working set in your Searches:

eclipse tips tricks tutorials

How to search for a class/package in a set of JAR files?

Provided that you are using the JAR files in a project as a library, then you can use the powerful Java search. Here's for example how to find where the org.apache.cxf.Bus class is contained :

eclipse search tips tricks

Depending on what is searched for, the search string should describe the element:
Type: the type name (may be qualified or not).
Example:    org.apache.cxf.Bus
 
Method: the defining type name (may be qualified or not as for Type search, optional), the method selector and its parameters
Example:  org.eclipse.jdt.internal.core.JavaElement.getHandleFromMemento(MementoTokenizer, WorkingCopyOwner)

Package: the package name for a package (e.g. org.eclipse.jdt.internal.core

Constructor: the defining type name (may be qualified or not as for Type search, optional) and the constructor parameters

Example: org.eclipse.jdt.internal.core.JavaElement(JavaElement, String)

How to find all classes that extend interface

Simply use Ctrl-T to get the descendants and then Ctrl-T again if super interfaces/classes are wanted:

eclipse search tutorial tips tricks

How to replace String in all files in Eclipse

Not everybody is aware that you can perform safe Search and Replace string patterns across a set of files. I mentioned "safe" because you are allowed to preview changes before executing the replace.

  1. Go to the Menu "Search"->"File"
  2. Enter text, file pattern and projects
  3. Click "Replace"
  4. Enter new text

eclipse tips tricks hints tutorials

How to exclude folders from Eclipse search

The simplest way to exclude a folder is: right click on a folder, go to properties, and mark a folder as derived. Derived

eclipse search tutorials tips

How to share the eclipse search result/ query

Have a look at the Mylyn project (http://eclipse.org/mylyn).

 

Mylyn is the task and application lifecycle management (ALM) framework for Eclipse. It allows you to create tasks and send them to co-workers through a task repository (such as bugzilla, jira, or most major issue trackers). Attached to these tasks are "contexts", which associate code elements (methods, fields, classes, etc) with the task.

 

Here are the steps needed to get started:

  1. Install mylyn (you and all co-workers)
  2. Install the proper Eclipse Connector for your issue tracker (such as SVN Eclipse connector).
  3. Now add the task repository to your Eclipse. This is the way that mylyn speaks to your issue tracker. It allows you to create issues, bug reports, tasks, etc, from within Eclipse.
  4. With this set up, you can now create a task associated with a task repository and activate it. You can add the desired program elements to your task by right clicking -> Mark as Landmark.

How to export/save Search Results

Out of the box there is no Save search functionality, however you can use the "Show Previous Searches" button at the top of the search console. It has a flashlight with a list above it. You can toggle between searches and Eclipse has already done all the heavy work.

eclipse search tips tricks


Advertisement
 

Search our tutorials