Get Module object for selected VirtualFiles

Hi,

I can get selected files by user using
VirtualFile[] files = (VirtualFile[]) dataContext
.getData(DataConstants.VIRTUAL_FILE_ARRAY);

Now i will like to know the Module to which the above selected files
belong to. How can I find this out.

TIA

Regards,
Yuvraj



6 comments

ModuleUtil.findModuleForFile(VirtualFile file, Project project)

0

This call returns null in some case
The scenario is I am trying to find out a module for a directory under classes dir.
The name of the directory is: VirtualFile: E:\AnchorRequired1\classes\production
both VirtualFile and project passed to findModuleForFile are appropriate.

I am not able to figure out why it returns null.

TIA

Regards,
Yuvraj

0

Have you tried:

ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(myFile)

?

0

Yes I have tried that too. That also returns null.

The directory whose module information I want is a directory in output folder. Is this causing a problem,if yes is there any other way to get module for a directory under output folder?

0

Hello Yuvraj,

This call returns null in some case
The scenario is I am trying to find out a module for a directory under
classes dir.
The name of the directory is: VirtualFile:
E:\AnchorRequired1\classes\production
both VirtualFile and project passed to findModuleForFile are
appropriate.
I am not able to figure out why it returns null.


It returns null because "classes" is an excluded directory. The files under
it are not processed by IDEA in any way.

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


0

Please sign in to leave a comment.