how to create a search-scope for a package?

I would like to search for all inheritors of a given class in a given package.

I would like to use :

ClassInheritorsSearch.search(aClass, packageScope, true).findAll()

but I don't find the way to create a scope (class SearchScope, for the second parameter of the method search above) corresponding to the package containing the given class (from aClass of type PsiClass).

I am not interested in searching in the whole project, just in a given package of the project.

aClass.getUseScope() gives me a too large scope.

Any clue?

6 comments
Comment actions Permalink

Collect the directories of a package, build a DirectoryScope for each of them and combine them with union().

0
Comment actions Permalink

Ok thanks.

And how do I get the directory from a class or from its file (PsiJavaFile) ?

0
Comment actions Permalink

Ok : getContainingDirectory() from the PsiJavaFile :-)

0
Comment actions Permalink

In Idea 10.5 there is GlobalSearchScope.directoryScope(PsiDirectory,bool), but I couldn't find it in Idea 11. How do I create a SearchScope from a directory in Idea 11 ?

0
Comment actions Permalink

GlobalSearchScopes.directoryScope

0

Please sign in to leave a comment.