Building packages tree

Hello,

In my plugin, I have to gather names of packages that contain at least one Java class. Moreover, it is required to have it up to date.

The very first solution was to find a package root and then traverse all of the sub-packages.

PsiPackage package = JavaPsiFacade.getInstance(project).findPackage("");
package.getSubPackages();

Unfortunately, this solution is very slow (or not fast enough) when there is a project with about 100 modules and thousands of packages. 

Do you know any better approach to building the packages tree? Is there any cache mechanism that will give me the tree without traversing the project every time? Of course, I know that I can build the tree at the beginning, cache it and create a listener that will update the structure when a directory/package will be created/removed/edited.

1 comment

Hi Bricky,

> Of course, I know that I can build the tree at the beginning,
> cache it and create a listener that will update the structure
> when a directory/package will be created/removed/edited.

So the only thing I can recommend to you is do not build the whole tree at the beginning.
You need only several top-level nodes, for example, root/modules/root-packages.
All child nodes should be build on demand, when someone expands the level above.

 

0

Please sign in to leave a comment.