VirtualFile (@NotNull Project project, @NotNull VirtualFile forFile) { GlobalSearchScope scope = GlobalSearchScope.allScope(project); if (scope.contains(forFile)) return forFile; VirtualFile canonicalForFile = forFile.getCanonicalFile(); if (canonicalForFile == null) canonicalForFile = forFile; Collection<VirtualFile> projectFiles = FilenameIndex.getVirtualFilesByName(canonicalForFile.getName(), scope); for (VirtualFile eachContentFile : projectFiles) { if (canonicalForFile.equals(eachContentFile.getCanonicalFile())) return eachContentFile; } return forFile; }