Search in sources :

Example 1 with LogicalRoot

use of com.intellij.util.LogicalRoot in project intellij-community by JetBrains.

the class IfsUtil method getReferencePath.

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LogicalRoot(com.intellij.util.LogicalRoot) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex)

Example 2 with LogicalRoot

use of com.intellij.util.LogicalRoot in project intellij-community by JetBrains.

the class JavaQualifiedNameProvider method findFile.

private static VirtualFile findFile(String fqn, Project project) {
    List<LogicalRoot> lr = LogicalRootsManager.getLogicalRootsManager(project).getLogicalRoots();
    for (LogicalRoot root : lr) {
        VirtualFile vfr = root.getVirtualFile();
        if (vfr == null)
            continue;
        VirtualFile virtualFile = vfr.findFileByRelativePath(fqn);
        if (virtualFile != null)
            return virtualFile;
    }
    for (VirtualFile root : ProjectRootManager.getInstance(project).getContentRoots()) {
        VirtualFile rel = root.findFileByRelativePath(fqn);
        if (rel != null) {
            return rel;
        }
    }
    VirtualFile file = LocalFileSystem.getInstance().findFileByPath(fqn);
    if (file != null)
        return file;
    PsiFile[] files = PsiShortNamesCache.getInstance(project).getFilesByName(fqn);
    for (PsiFile psiFile : files) {
        VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile != null)
            return virtualFile;
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LogicalRoot(com.intellij.util.LogicalRoot)

Example 3 with LogicalRoot

use of com.intellij.util.LogicalRoot in project intellij-community by JetBrains.

the class CopyReferenceAction method getVirtualFileFqn.

private static String getVirtualFileFqn(@NotNull VirtualFile virtualFile, @NotNull Project project) {
    final LogicalRoot logicalRoot = LogicalRootsManager.getLogicalRootsManager(project).findLogicalRoot(virtualFile);
    VirtualFile logicalRootFile = logicalRoot != null ? logicalRoot.getVirtualFile() : null;
    if (logicalRootFile != null && !virtualFile.equals(logicalRootFile)) {
        return ObjectUtils.assertNotNull(VfsUtilCore.getRelativePath(virtualFile, logicalRootFile, '/'));
    }
    VirtualFile outerMostRoot = null;
    VirtualFile each = virtualFile;
    ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
    while (each != null && (each = index.getContentRootForFile(each, false)) != null) {
        outerMostRoot = each;
        each = each.getParent();
    }
    if (outerMostRoot != null && !outerMostRoot.equals(virtualFile)) {
        String relative = VfsUtilCore.getRelativePath(virtualFile, outerMostRoot, '/');
        if (relative != null) {
            return relative;
        }
    }
    return virtualFile.getPath();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LogicalRoot(com.intellij.util.LogicalRoot) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 LogicalRoot (com.intellij.util.LogicalRoot)3 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)2