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?

 

0
2 comments
Avatar
Permanently deleted user

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...

 

0

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

0

Please sign in to leave a comment.