私は現在、JDTに基づくカスタムリファクタリングツールに取り組んでいます。ある時点で、Eclipseの「TypeHierarchy」ビューと同じように、タイプのすべてのサブタイプを見つけたいと思います。SearchEngineを使用して、階層を通過する再帰関数を作成しました。これは機能しますが、深い階層では非常に遅くなります。使用できるより効率的なAPIはありますか?
private Set<IType> searchForSubTypesOf(IType type, IProgressMonitor monitor) throws CoreException {
final Set<IType> result = new HashSet<IType>();
SearchPattern pattern = SearchPattern.createPattern(type, IJavaSearchConstants.REFERENCES, SearchPattern.R_EXACT_MATCH);
SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
IJavaSearchScope scope = SearchEngine.createHierarchyScope(inputType);
SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
if (match.getAccuracy() == SearchMatch.A_ACCURATE && match.getElement() instanceof IType) {
IType subType = (IType)match.getElement();
result.add(subType);
// Recursive search for the type found
Set<IType> subTypes = searchForSubTypesOf(subType, new NullProgressMonitor());
result.addAll(subTypes);
}
}
};
new SearchEngine().search(pattern, participants, scope, requestor, monitor);
return result;
}