[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools.jdt] Re: Programmatically search for method references

For SearchParticipant, you can use the default value created by
SearchEngine#getDefaultSearchParticipant().

For the requestor just override the acceptSearchMatch method as follow:
	SearchRequestor requestor = new SearchRequestor() {
		public void acceptSearchMatch(SearchMatch match) throws CoreException {
			// insert your specific code to treat the returned match here...
		}
	};

So, an example could be:
SearchPattern pattern = SearchPattern.createPattern(
	"foo",
	IJavaSearchConstants.METHOD,
	IJavaSearchConstants.REFERENCES,
	SearchPattern.R_EXACT_MATCH);
new SearchEngine().search(pattern
			  new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
			  SearchEngine.createWorkspaceScope(),
			  requestor,
			  null); // no progress monitor
This should return references to all methods 'foo' (whatever the number of parameters
they have and the type in which they are defined...).

So, I would say that SearchEngine#search(...) method is enough to address your need.
Of course, this works only if you put the JDT/Core plug-in as required for
your plug-in where you intend to implement this code...

JDT/UI Find*Action classes are defined in JDT/UI plug-in and correspond to
the actions in the Search menu you get on each Java Element (type/method/field).
But each of these actions finally calls the search(...) method of SearchEngine...


Rudolf Ziegaus wrote:
Hi,

I want to create a plugin that allows me search programmatically for method
references.

Since I have no experience in plugins I'be happy if you could give me a
hint where to start. Right now I have found the method search in
SearchEngine, public void search(SearchPattern pattern,
SearchParticipant[] participants,
IJavaSearchScope scope,
SearchRequestor requestor,
IProgressMonitor monitor)


but I don't know which value I should supply for SearchParticipant[] and
SearchRequestor.
I also have found the classes FindReferencesInProjectAction and
FindReferencesAction.

Which way would be the best for me? Or maybe you know an even better one?

Thanks for all hints,

Rudi