VirtualFile (@NotNull VirtualFile virtualFile, @NotNull Project project) { ProjectFileIndex index = ProjectFileIndex.getInstance(project); VirtualFile root = index.getContentRootForFile(virtualFile); if (root == null) root = index.getClassRootForFile(virtualFile); if (root == null) root = index.getSourceRootForFile(virtualFile); if (root == null || !root.isDirectory()) { root = BaseProjectDirectories.getInstance(project).getBaseDirectoryFor(virtualFile); } return root; }