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

Am Thu, 16 Aug 2007 14:01:37 +0200 schrieb Frederic Fusier:

> 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...

Hello Frederic,

thanks for your answer. I already figured out some of your information
myself and I am pleased that I got it right.

As you certainly already have guessed, I am a newbie to writing plugins for
Eclipse. I am trying to write a plugin which allows me to detect
unreferenced public methods (unreferenced in the workspace - of course
nobody could garantee that it is not referenced in a different workspace or
via reflection). 

I  found out how to get all projects in the workspace and the contained
classes in a project. However, I do not know how to find out which methods
they contain. The files are represented as IResource however to look at the
contained methods I would need a IType. How do I get from an IResource to
an IType?

Can you give me some clues, also on documentation where I could read
further before asking dump questions here?

Thanks very much,

Rudi