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.
I have the following module ibrary defined
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?
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
"Develop with pleasure!"
That works fine.