[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools.jdt] Re: Searching for implementers of Abstract methods

Michael Desmond wrote:

Hi,

Does anyone know of a component in the JDT that will allow me to resolve the concrete methods which implement a given abstract method??

Thanks
Mike

I think you can use JDT/Core Search Engine to do this.

For this, you need to search for methods in hierarchy and filter only concrete ones
API method to perform this kind of search is
	SearchEngine.search(
		SearchPattern pattern,
		SearchParticipant[] participants,
		IJavaSearchScope scope,
		SearchRequestor requestor,
		IProgressMonitor monitor)

Pattern could be:
	SearchPattern pattern = SearchPattern.createPattern(
		method,
		IJavaSearchConstants#DECLARATIONS,
		SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
  (where method is the IMethod of the given abstract method)

Participants could be:
	new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }

Scope could be:
	SearchEngine.createHierarchyScope(type)
  (where type is the IType of your abstract method - ie. its parent)

Requestor could be:
	requestor = new SearchRequestor() {
		public abstract void acceptSearchMatch(SearchMatch match) throws CoreException {
			if (match.getElement() instanceof IMethod) {
				IMethod method = (IMethod) match.getElement();
				if (!Flags.isAbstract(method.getFlags()) {
					// That's it...!
				}
			}
		}
	}

HTH