Module for file in fileCreated?
I implemented VirtualFileListener in a Component and in its fileCreated() method I need to know the root path for the module where the file is created. My code is:
Module module = ProjectRootManager.getInstance(MyComponent.this.myProject).getFileIndex().getModuleForFile(event.getFile());
For some reason it returns null. Is it a bug or is it by design? And is there any alternative way to get the Module content path?
Please sign in to leave a comment.
OK, I found the problem. When I create a file, the event gets generated for ALL open projects, but obviously the file that I create only belongs to one of them. I have a feeling this is a bug...
VFS is application-wide, see http://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/virtual_file.html
you can filter relevant project by com.intellij.openapi.project.ProjectUtil#guessProjectForFile