2

私は現在、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;
}
4

1 に答える 1

3

たくさんのコードを読んだ後、私はこれらの素晴らしい瞬間の1つを経験し、ついに私が探していたAPIを見つけました!

上記の私の関数はこれに要約されます:

public static IType[] getAllSubtypesOf(IType type, IProgressMonitor monitor) throws CoreException {
    return type.newTypeHierarchy(monitor).getAllSubtypes(type);
}
于 2013-03-26T13:55:29.097 に答える