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

The following examples show how to use com.intellij.openapi.vfs.VirtualFile#getCanonicalFile() . 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 File: BsPlatform.java    From reasonml-idea-plugin with 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
Source File: CamelPropertyPlaceholderSmartCompletionExtension.java    From camel-idea-plugin with Apache License 2.0 6 votes vote down vote up
@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 File: GoToLinkTargetAction.java    From consulo with 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 File: BlazeProblemsView.java    From intellij with 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;
}