Java Code Examples for com.intellij.openapi.vfs.VirtualFile#getCanonicalFile()

The following examples show how to use com.intellij.openapi.vfs.VirtualFile#getCanonicalFile() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: reasonml-idea-plugin   File: BsPlatform.java    License: MIT License 6 votes vote down vote up
private static Optional<VirtualFile> findBsPlatformPathForConfigFile(@NotNull VirtualFile bsConfigFile) {
    VirtualFile parentDir = bsConfigFile.getParent();
    VirtualFile bsPlatform = parentDir.findFileByRelativePath("node_modules/" + BS_PLATFORM_DIRECTORY_NAME);
    if (bsPlatform == null) {
        VirtualFile bsbBinary = parentDir.findFileByRelativePath("node_modules/.bin/bsb"); // In case of mono-repo, only the .bin with symlinks is found
        if (bsbBinary != null && bsbBinary.is(VFileProperty.SYMLINK)) {
            VirtualFile canonicalFile = bsbBinary.getCanonicalFile();
            if (canonicalFile != null) {
                VirtualFile canonicalBsPlatformDirectory = canonicalFile.getParent();
                while (canonicalBsPlatformDirectory != null && !canonicalBsPlatformDirectory.getName().equals(BS_PLATFORM_DIRECTORY_NAME)) {
                    canonicalBsPlatformDirectory = canonicalBsPlatformDirectory.getParent();
                }
                return Optional.ofNullable(canonicalBsPlatformDirectory);
            }
        }
    }

    return Optional.ofNullable(bsPlatform).filter(VirtualFile::isDirectory);
}
 
Example 2
@Override
public void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet resultSet, @NotNull String[] query) {
    Project project = parameters.getOriginalFile().getManager().getProject();

    List<VirtualFile> resourceRoots = ProjectRootManager.getInstance(project).getModuleSourceRoots(JavaModuleSourceRootTypes.PRODUCTION);
    resourceRoots.addAll(ProjectRootManager.getInstance(project).getModuleSourceRoots(JavaModuleSourceRootTypes.TESTS));
    ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    for (final VirtualFile sourceRoot : resourceRoots) {
        if (sourceRoot.isValid() && sourceRoot.getCanonicalFile() != null) {
            VfsUtil.processFilesRecursively(sourceRoot.getCanonicalFile(), virtualFile -> {
                propertyCompletionProviders.stream()
                    .filter(p -> p.isValidExtension(virtualFile.getCanonicalPath()) && !projectFileIndex.isExcluded(sourceRoot))
                    .forEach(p -> p.buildResultSet(resultSet, virtualFile));
                return true;
            });
        }
    }
}
 
Example 3
Source Project: consulo   File: GoToLinkTargetAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  Project project = getEventProject(e);
  VirtualFile file = e.getDataContext().getData(CommonDataKeys.VIRTUAL_FILE);
  if (project != null && file != null && file.is(VFileProperty.SYMLINK)) {
    VirtualFile target = file.getCanonicalFile();
    if (target != null) {
      PsiManager psiManager = PsiManager.getInstance(project);
      PsiFileSystemItem psiFile = target.isDirectory() ? psiManager.findDirectory(target) : psiManager.findFile(target);
      if (psiFile != null) {
        ProjectView.getInstance(project).select(psiFile, target, false);
      }
    }
  }
}
 
Example 4
Source Project: intellij   File: BlazeProblemsView.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Attempts to resolve symlinks in the virtual file path, falling back to returning the original
 * virtual file if unsuccessful.
 */
private static VirtualFile resolveSymlinks(VirtualFile file) {
  VirtualFile resolved = file.getCanonicalFile();
  return resolved != null ? resolved : file;
}