六年过去了,所以这可能对你没有多大帮助。也许它会帮助别人......
我在这里有许多有用的 Eclipse JDT 搜索方法,它们使用SearchEngine等。例如:
/**
* Collects the methods that access the specified member
* @param element the field or method whose accessors are being determined
* @param scope the elements being examined, e.g. this class or this package
* @return the collection of methods that access the indicated member
*/
public static Set<IMethod> calculateCallingMethods(
IJavaElement element,
IJavaSearchScope scope)
throws CoreException {
SearchEngine searchEngine = new SearchEngine();
SearchParticipant[] participants =
new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
SearchPattern callingMethodPattern = SearchPattern.createPattern(
element, REFERENCES);
MethodCollector methodCollector = new MethodCollector();
searchEngine.search(callingMethodPattern, participants, scope,
methodCollector, null);
Set<IMethod> callers = methodCollector.getResults();
return callers;
}