Search code examples
eclipseeclipse-plugineclipse-pde

How can I get the results of a search in eclipse


I am developing a eclipse plugin, I need to get or store the results of a query search (java seach ctrl+H) in eclipse.

Once I made a search (java seach ctrl+H) I need to get or store the results in a data structure so as to manipulate it.

java search method add:

Image

I need to manipulate this results in a data structure:

Image

I only need to look for methods.


Solution

  • You can listen to searches using:

    NewSearchUI.addQueryListener(listener);
    

    where listener is a class implementing IQueryListener. This interface has a number of methods called as queries progress. They all have an ISearchQuery parameter. ISearchQuery has the method

    ISearchResult getSearchResult()
    

    which you can call to get the search result ISearchResult. This has a

    void addListener(ISearchResultListener listener)
    

    method which lets you listen to the results changing using the:

    void searchResultChanged(SearchResultEvent event)
    

    method of the interface. SearchResultEvent is an abstract class which does not contain much information. Depending on the type of result changing the actual class might be something like org.eclipse.search.ui.text.MatchEvent which contains more information.