how to get list of packages

so i was thinking about a plugin and i want to get a list of all packages in the current project, how would i go about that? i've been looking through the api but it is not really clear to me at this point.

thanks
-Andre

0
4 comments
Avatar
Permanently deleted user

Have you looked at the PSI API?


Timur

so i was thinking about a plugin and i want to get a
list of all packages in the current project, how
would i go about that? i've been looking through the
api but it is not really clear to me at this point.

thanks
-Andre

0
Avatar
Permanently deleted user

I could be totally wrong here but it could be something like this:

1) Get all source roots.
2) Get psiElements for them.
3) Process their children till you get all packages.


Timur

0

Hey thanks for the tips, appreciate it, i'm trying to understand how the method findClass(java.lang.String) of PsiManager works, i've tried giving it virtualFile.getNAme and virtualFile.getNameWithoutExtension neither seems to be working. any clues? thanks

-Andre

0
Avatar
Permanently deleted user

virtualFile.getName() returns something like "List.java". I guess getNameWithoutExtension() will return "List". I would also try a fully qualified class name (e.g. "java.util.List").


Timur

Hey thanks for the tips, appreciate it, i'm trying to
understand how the method findClass(java.lang.String)
of PsiManager works, i've tried giving it
virtualFile.getNAme and
virtualFile.getNameWithoutExtension neither seems to
be working. any clues? thanks

-Andre

0

Please sign in to leave a comment.