Java 类com.intellij.util.LogicalRootsManager 实例源码

项目:intellij-ce-playground    文件:IfsUtil.java   
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();
}
项目:tools-idea    文件:CopyReferenceAction.java   
@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();
}
项目:tools-idea    文件:IfsUtil.java   
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();
}
项目:consulo    文件:QualifiedNameProviders.java   
@Nonnull
public 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();
}
项目:intellij-ce-playground    文件:SameLogicalRootWeigher.java   
@Nullable
private static LogicalRoot findLogicalRoot(PsiElement element) {
  if (element == null) return null;

  final PsiFile psiFile = element.getContainingFile();
  if (psiFile == null) return null;

  final VirtualFile file = psiFile.getVirtualFile();
  if (file == null) return null;

  return LogicalRootsManager.getLogicalRootsManager(element.getProject()).findLogicalRoot(file);
}
项目:tools-idea    文件:SameLogicalRootWeigher.java   
@Nullable
private static LogicalRoot findLogicalRoot(PsiElement element) {
  if (element == null) return null;

  final PsiFile psiFile = element.getContainingFile();
  if (psiFile == null) return null;

  final VirtualFile file = psiFile.getVirtualFile();
  if (file == null) return null;

  return LogicalRootsManager.getLogicalRootsManager(element.getProject()).findLogicalRoot(file);
}
项目:consulo    文件:SameLogicalRootWeigher.java   
@Nullable
private static LogicalRoot findLogicalRoot(PsiElement element) {
  if (element == null) return null;

  final PsiFile psiFile = element.getContainingFile();
  if (psiFile == null) return null;

  final VirtualFile file = psiFile.getVirtualFile();
  if (file == null) return null;

  return LogicalRootsManager.getLogicalRootsManager(element.getProject()).findLogicalRoot(file);
}