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("");
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.