@NotNull private static String getFileFqn(final PsiFile file) { final VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile == null) { return file.getName(); } final Project project = file.getProject(); final LogicalRoot logicalRoot = LogicalRootsManager.getLogicalRootsManager(project).findLogicalRoot(virtualFile); if (logicalRoot != null) { String logical = FileUtil.toSystemIndependentName( VfsUtil.virtualToIoFile(logicalRoot.getVirtualFile()).getPath()); String path = FileUtil.toSystemIndependentName(VfsUtil.virtualToIoFile(virtualFile).getPath()); return "/" + FileUtil.getRelativePath(logical, path, '/'); } final VirtualFile contentRoot = ProjectRootManager.getInstance(project).getFileIndex().getContentRootForFile(virtualFile); if (contentRoot != null) { return "/" + FileUtil.getRelativePath( VfsUtil.virtualToIoFile(contentRoot), VfsUtil.virtualToIoFile(virtualFile)); } return virtualFile.getPath(); }
public static String getReferencePath(Project project, VirtualFile file) { final LogicalRoot logicalRoot = LogicalRootsManager.getLogicalRootsManager(project).findLogicalRoot(file); if (logicalRoot != null) { return getRelativePath(file, logicalRoot.getVirtualFile()); } ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); VirtualFile sourceRoot = fileIndex.getSourceRootForFile(file); if (sourceRoot != null) { return getRelativePath(file, sourceRoot); } VirtualFile root = fileIndex.getContentRootForFile(file); if (root != null) { return getRelativePath(file, root); } return file.getPath(); }
public Comparable weigh(@NotNull final PsiElement element, final ProximityLocation location) { final LogicalRoot elementRoot = findLogicalRoot(element); final LogicalRoot contextRoot = findLogicalRoot(location.getPosition()); return elementRoot != null && contextRoot != null && elementRoot.equals(contextRoot); }