Checking if PsiClass is still in the classpath

In my plugin i'm caching instances of PsiClass in some places, but when i use the cached instance i want to find out if the class is still available to the module.

This is easy for source types because i need to do is check if the file associated to the PsiClass is still there.
But when the PsiClass is a binary type that got returned from some library in the classpath things get more complicated.

How can i check that the PsiClass is still on the module classpath ? The user could have just removed the library from the classpath. I've tried getting this information from the PsiClass itself but all the methods i've tried still return the same result even after the library is removed from the classpath.

4 comments

Hello Hugo,

HP> In my plugin i'm caching instances of PsiClass in some places, but
HP> when i use the cached instance i want to find out if the class is
HP> still available to the module.
HP>
HP> This is easy for source types because i need to do is check if the
HP> file associated to the PsiClass is still there.
HP>
HP> But when the PsiClass is a binary type that got returned from some
HP> library in the classpath things get more complicated.
HP>
HP> How can i check that the PsiClass is still on the module classpath ?
HP> The user could have just removed the library from the classpath.
HP> I've tried getting this information from the PsiClass itself but all
HP> the methods i've tried still return the same result even after the
HP> library is removed from the classpath.

PsiManager.findClass(myClass.getQualifiedName(), GlobalSearchScope.moduleWithLibrariesScope(myModule))
!= null

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0

I thought of that, but i'm afraid that that would have an impact on the plugin performance, as i'd have to search for the class again.

I don't have any metrics for the findClass operation, but do you think that it's fast enough for me to use it like that ? Does it use some kind of caching or does it go through all the source and libraries tree every time it's called ?

Thanks

0

Hello Hugo,

HP> I thought of that, but i'm afraid that that would have an impact on
HP> the plugin performance, as i'd have to search for the class again.
HP>
HP> I don't have any metrics for the findClass operation, but do you
HP> think that it's fast enough for me to use it like that ? Does it use
HP> some kind of caching or does it go through all the source and
HP> libraries tree every time it's called ?

It's cached and quite efficient.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0

That's enough for me.

Thanks again.

0

Please sign in to leave a comment.