4 comments
Comment actions Permalink

Martin Fuhrer wrote:

Does anybody know how to get the corresponding Module of a given PsiClass?


There's com.intellij.openapi.vfs.VfsUtil.getModuleForFile(Project, VirtualFile).
You should be able to get the VirtualFile instance of your class by calling
PsiClass.getContainingFile().getVirtualFile()

HTH,
Sascha

PS: I found this using a Structural Search for all methods returning a Module ;)

0
Comment actions Permalink

Thanks a lot, works like a charm!

Sascha Weinreuter wrote:

Martin Fuhrer wrote:

>>Does anybody know how to get the corresponding Module of a given PsiClass?


There's com.intellij.openapi.vfs.VfsUtil.getModuleForFile(Project, VirtualFile).
You should be able to get the VirtualFile instance of your class by calling
PsiClass.getContainingFile().getVirtualFile()

HTH,
Sascha

PS: I found this using a Structural Search for all methods returning a Module ;)


--
Martin Fuhrer
Fuhrer Engineering AG
http://www.fuhrer.com

0
Comment actions Permalink

For those who hit this page,

com.intellij.openapi.vfs.VfsUtil.getModuleForFile()

was refactored to the following couple:


final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();

final Module module = index.getModuleForFile(virtualFile);

Check out https://confluence.jetbrains.com/display/IDEADEV/Diana+Plugin+Migration+Guide

0
Comment actions Permalink

this works too:

ModuleUtil.findModuleForFile(VirtualFile, Project);

0

Please sign in to leave a comment.