How to get path to jar file containing a class?

I've got a reference to the VirtualFile representing a .java file. I want to determine the path of the library jar that contains the corresponding .class file.

eg.
I have the following module ibrary defined
example.jar
c:\source\example <-- source corresponding to example.jar

for a VirtualFile in c:\source\example, how do I determine that example.jar contains the class file?

2 comments
Comment actions Permalink

There's getOriginalElement() method in PsiElement serving exactly this purpose
and getNavigationElement() for backward conversion.

Thus you need to take PsiFile for your VirtualFile and take PsiClass from
it and call getOriginalElement() from the class and then getContainingFile()
to get PsiFile for .class and getVirtualFile() to get virtual file back from
PsiFile.

-


Maxim Shafirov
http://www.jetbrains.com
"Develop with pleasure!"

I've got a reference to the VirtualFile representing a .java file. I
want to determine the path of the library jar that contains the
corresponding .class file.

eg.
I have the following module ibrary defined
example.jar
c:\source\example <-- source corresponding to example.jar
for a VirtualFile in c:\source\example, how do I determine that
example.jar contains the class file?



0
Comment actions Permalink

Thanks Maxim,

That works fine.

0

Please sign in to leave a comment.