com.intellij.openapi.vfs.VFileProperty Java Examples

The following examples show how to use com.intellij.openapi.vfs.VFileProperty. 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: PsiFileNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateImpl(PresentationData data) {
  PsiFile value = getValue();
  data.setPresentableText(value.getName());
  data.setIcon(IconDescriptorUpdaters.getIcon(value, Iconable.ICON_FLAG_READ_STATUS));

  VirtualFile file = getVirtualFile();
  if (file != null && file.is(VFileProperty.SYMLINK)) {
    String target = file.getCanonicalPath();
    if (target == null) {
      data.setAttributesKey(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
      data.setTooltip(CommonBundle.message("vfs.broken.link"));
    }
    else {
      data.setTooltip(FileUtil.toSystemDependentName(target));
    }
  }
}
 
Example #3
Source File: AbstractPsiBasedNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static Image patchIcon(@Nonnull Project project, @Nullable Image original, @Nullable VirtualFile file) {
  if (file == null || original == null) return original;

  IconDescriptor iconDescriptor = new IconDescriptor(original);

  final Bookmark bookmarkAtFile = BookmarkManager.getInstance(project).findFileBookmark(file);
  if (bookmarkAtFile != null) {
    iconDescriptor.setRightIcon(bookmarkAtFile.getIcon());
  }

  if (!file.isWritable()) {
    iconDescriptor.addLayerIcon(AllIcons.Nodes.Locked);
  }

  if (file.is(VFileProperty.SYMLINK)) {
    iconDescriptor.addLayerIcon(AllIcons.Nodes.Symlink);
  }

  return iconDescriptor.toIcon();
}
 
Example #4
Source File: LoadAllVfsStoredContentsAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean processFile(NewVirtualFile file) {
  if (file.isDirectory() || file.is(VFileProperty.SPECIAL)) {
    return true;
  }
  try {
    try (InputStream stream = PersistentFS.getInstance().getInputStream(file)) {
      // check if it's really cached in VFS
      if (!(stream instanceof DataInputStream)) return true;
      byte[] bytes = FileUtil.loadBytes(stream);
      totalSize.addAndGet(bytes.length);
      count.incrementAndGet();
      ProgressManager.getInstance().getProgressIndicator().setText(file.getPresentableUrl());
    }
  }
  catch (IOException e) {
    LOG.error(e);
  }
  return true;
}
 
Example #5
Source File: PsiFileIconDescriptorUpdater.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Override
public void updateIcon(@Nonnull IconDescriptor iconDescriptor, @Nonnull PsiElement element, int flags) {
  if (element instanceof PsiFile) {
    if (iconDescriptor.getMainIcon() == null) {
      FileType fileType = ((PsiFile)element).getFileType();
      iconDescriptor.setMainIcon(fileType.getIcon());
    }

    VirtualFile virtualFile = ((PsiFile)element).getVirtualFile();
    if (virtualFile != null && virtualFile.is(VFileProperty.SYMLINK)) {
      iconDescriptor.addLayerIcon(AllIcons.Nodes.Symlink);
    }
  }
  else {
    Image languageElementIcon = LanguageElementIcons.INSTANCE.forLanguage(element.getLanguage());
    if (languageElementIcon == null) {
      return;
    }

    iconDescriptor.addLayerIcon(languageElementIcon);
  }
}
 
Example #6
Source File: AbstractFileViewProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
protected PsiFile createFile(@Nonnull VirtualFile file, @Nonnull FileType fileType, @Nonnull Language language) {
  if (fileType.isBinary() || file.is(VFileProperty.SPECIAL)) {
    return SingleRootFileViewProvider.isTooLargeForContentLoading(file) ? new PsiLargeBinaryFileImpl((PsiManagerImpl)getManager(), this) : new PsiBinaryFileImpl((PsiManagerImpl)getManager(), this);
  }
  if (!SingleRootFileViewProvider.isTooLargeForIntelligence(file)) {
    final PsiFile psiFile = createFile(language);
    if (psiFile != null) return psiFile;
  }

  if (SingleRootFileViewProvider.isTooLargeForContentLoading(file)) {
    return new PsiLargeTextFileImpl(this);
  }

  return new PsiPlainTextFileImpl(this);
}
 
Example #7
Source File: FileTreeModel.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean updateContent(State state) {
  VirtualFile file = getFile();
  if (file == null) return updateName(state.descriptor.getTitle());

  Image icon = state.descriptor.getIcon(file);
  String name = state.descriptor.getName(file);
  String comment = state.descriptor.getComment(file);
  if (name == null || comment == null) name = file.getName();

  boolean updated = false;
  if (updateIcon(icon)) updated = true;
  if (updateName(name)) updated = true;
  if (updateComment(comment)) updated = true;
  if (updateValid(file.isValid())) updated = true;
  if (updateHidden(FileElement.isFileHidden(file))) updated = true;
  if (updateSpecial(file.is(VFileProperty.SPECIAL))) updated = true;
  if (updateSymlink(file.is(VFileProperty.SYMLINK))) updated = true;
  if (updateWritable(file.isWritable())) updated = true;
  return updated;
}
 
Example #8
Source File: VfsImplUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static NewVirtualFile findFileByPath(@Nonnull NewVirtualFileSystem vfs, @Nonnull String path) {
  Pair<NewVirtualFile, Iterable<String>> data = prepare(vfs, path);
  if (data == null) return null;

  NewVirtualFile file = data.first;
  for (String pathElement : data.second) {
    if (pathElement.isEmpty() || ".".equals(pathElement)) continue;
    if ("..".equals(pathElement)) {
      if (file.is(VFileProperty.SYMLINK)) {
        final NewVirtualFile canonicalFile = file.getCanonicalFile();
        file = canonicalFile != null ? canonicalFile.getParent() : null;
      }
      else {
        file = file.getParent();
      }
    }
    else {
      file = file.findChild(pathElement);
    }

    if (file == null) return null;
  }

  return file;
}
 
Example #9
Source File: FileChooserDescriptor.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Defines whether file can be chosen or not
 */
@RequiredUIAccess
public boolean isFileSelectable(VirtualFile file) {
  if (file == null) return false;

  if (file.is(VFileProperty.SYMLINK) && file.getCanonicalPath() == null) {
    return false;
  }
  if (file.isDirectory() && myChooseFolders) {
    return true;
  }

  if (myFileFilter != null && !file.isDirectory()) {
    return myFileFilter.value(file);
  }

  return acceptAsJarFile(file) || acceptAsGeneralFile(file);
}
 
Example #10
Source File: EditSourceUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean canNavigate (PsiElement element) {
  if (element == null || !element.isValid()) {
    return false;
  }

  VirtualFile file = PsiUtilCore.getVirtualFile(element.getNavigationElement());
  return file != null && file.isValid() && !file.is(VFileProperty.SPECIAL) && !VfsUtilCore.isBrokenLink(file);
}
 
Example #11
Source File: MetadataContainerInfo.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
private static VirtualFile findMetadataFile(VirtualFile root, String metadataFileName) {
  if (!root.is(VFileProperty.SYMLINK)) {
    //noinspection UnsafeVfsRecursion
    for (VirtualFile child : asList(root.getChildren())) {
      if (child.getName().equals(metadataFileName)) {
        return child;
      }
      VirtualFile matchedFile = findMetadataFile(child, metadataFileName);
      if (matchedFile != null) {
        return matchedFile;
      }
    }
  }
  return null;
}
 
Example #12
Source File: NavBarPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
static Object expandDirsWithJustOneSubdir(Object target) {
  if (target instanceof PsiElement && !((PsiElement)target).isValid()) return target;
  if (target instanceof PsiDirectory) {
    PsiDirectory directory = (PsiDirectory)target;
    for (VirtualFile file = directory.getVirtualFile(), next; ; file = next) {
      VirtualFile[] children = file.getChildren();
      VirtualFile child = children.length == 1 ? children[0] : null;
      //noinspection AssignmentToForLoopParameter
      next = child != null && child.isDirectory() && !child.is(VFileProperty.SYMLINK) ? child : null;
      if (next == null) return ObjectUtils.notNull(directory.getManager().findDirectory(file), directory);
    }
  }
  return target;
}
 
Example #13
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 #14
Source File: LoadAllContentsAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  final Project project = e.getDataContext().getData(CommonDataKeys.PROJECT);
  String m = "Started loading content";
  LOG.info(m);
  System.out.println(m);
  long start = System.currentTimeMillis();
  count.set(0);
  totalSize.set(0);
  ApplicationManagerEx.getApplicationEx().runProcessWithProgressSynchronously(new Runnable() {
    @Override
    public void run() {
      ProjectRootManager.getInstance(project).getFileIndex().iterateContent(new ContentIterator() {
        @Override
        public boolean processFile(VirtualFile fileOrDir) {
          if (fileOrDir.isDirectory() || fileOrDir.is(VFileProperty.SPECIAL)) return true;
          try {
            count.incrementAndGet();
            byte[] bytes = FileUtil.loadFileBytes(new File(fileOrDir.getPath()));
            totalSize.addAndGet(bytes.length);
            ProgressManager.getInstance().getProgressIndicator().setText(fileOrDir.getPresentableUrl());
          }
          catch (IOException e1) {
            LOG.error(e1);
          }
          return true;
        }
      });
     }
  }, "Loading", false, project);
  long end = System.currentTimeMillis();
  String message = "Finished loading content of " + count + " files. Total size=" + StringUtil.formatFileSize(totalSize.get()) +
                   ". Elapsed=" + ((end - start) / 1000) + "sec.";
  LOG.info(message);
  System.out.println(message);
}
 
Example #15
Source File: LocalFileSystemRefreshWorker.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Path fixCaseIfNeeded(@Nonnull Path path, @Nonnull VirtualFile file) throws IOException {
  if (SystemInfo.isFileSystemCaseSensitive) return path;
  // Mac: toRealPath() will return the current file's name w.r.t. case
  // Win: toRealPath(LinkOption.NOFOLLOW_LINKS) will return the current file's name w.r.t. case
  return file.is(VFileProperty.SYMLINK) ? path.toRealPath(LinkOption.NOFOLLOW_LINKS) : path.toRealPath();
}
 
Example #16
Source File: VfsImplUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static NewVirtualFile refreshAndFindFileByPath(@Nonnull NewVirtualFileSystem vfs, @Nonnull String path) {
  Pair<NewVirtualFile, Iterable<String>> data = prepare(vfs, path);
  if (data == null) return null;

  NewVirtualFile file = data.first;
  for (String pathElement : data.second) {
    if (pathElement.isEmpty() || ".".equals(pathElement)) continue;
    if ("..".equals(pathElement)) {
      if (file.is(VFileProperty.SYMLINK)) {
        final String canonicalPath = file.getCanonicalPath();
        final NewVirtualFile canonicalFile = canonicalPath != null ? refreshAndFindFileByPath(vfs, canonicalPath) : null;
        file = canonicalFile != null ? canonicalFile.getParent() : null;
      }
      else {
        file = file.getParent();
      }
    }
    else {
      file = file.refreshAndFindChild(pathElement);
    }

    if (file == null) return null;
  }

  return file;
}
 
Example #17
Source File: VfsImplUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static Pair<NewVirtualFile, NewVirtualFile> findCachedFileByPath(@Nonnull NewVirtualFileSystem vfs, @Nonnull String path) {
  Pair<NewVirtualFile, Iterable<String>> data = prepare(vfs, path);
  if (data == null) return Pair.empty();

  NewVirtualFile file = data.first;
  for (String pathElement : data.second) {
    if (pathElement.isEmpty() || ".".equals(pathElement)) continue;

    NewVirtualFile last = file;
    if ("..".equals(pathElement)) {
      if (file.is(VFileProperty.SYMLINK)) {
        String canonicalPath = file.getCanonicalPath();
        NewVirtualFile canonicalFile = canonicalPath != null ? findCachedFileByPath(vfs, canonicalPath).first : null;
        file = canonicalFile != null ? canonicalFile.getParent() : null;
      }
      else {
        file = file.getParent();
      }
    }
    else {
      file = file.findChildIfCached(pathElement);
    }

    if (file == null) return pair(null, last);
  }

  return pair(file, null);
}
 
Example #18
Source File: FileChooserDescriptor.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Defines whether file is visible in the tree
 */
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
  if (file.is(VFileProperty.SYMLINK) && file.getCanonicalPath() == null) {
    return false;
  }

  if (!file.isDirectory()) {
    if (FileElement.isArchive(file)) {
      if (!myChooseJars && !myChooseJarContents) {
        return false;
      }
    }
    else if (!myChooseFiles) {
      return false;
    }

    if (myFileFilter != null && !myFileFilter.value(file)) {
      return false;
    }
  }

  if (isHideIgnored() && FileTypeManager.getInstance().isFileIgnored(file)) {
    return false;
  }

  if (!showHiddenFiles && FileElement.isFileHidden(file)) {
    return false;
  }

  return true;
}
 
Example #19
Source File: FileTypeManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean isDetectable(@Nonnull final VirtualFile file) {
  if (file.isDirectory() || !file.isValid() || file.is(VFileProperty.SPECIAL) || file.getLength() == 0) {
    // for empty file there is still hope its type will change
    return false;
  }
  return file.getFileSystem() instanceof FileSystemInterface;
}
 
Example #20
Source File: FileStatusManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static FileStatus getDefaultStatus(@Nonnull final VirtualFile file) {
  return file.isValid() && file.is(VFileProperty.SPECIAL) ? FileStatus.IGNORED : FileStatus.NOT_CHANGED;
}
 
Example #21
Source File: PsiUtilBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isSymLink(@Nonnull final PsiFileSystemItem element) {
  final VirtualFile virtualFile = element.getVirtualFile();
  return virtualFile != null && virtualFile.is(VFileProperty.SYMLINK);
}
 
Example #22
Source File: FileChooserDescriptor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
protected static Image dressIcon(final VirtualFile file, final Image baseIcon) {
  return file.isValid() && file.is(VFileProperty.SYMLINK) ? ImageEffects.layered(baseIcon, AllIcons.Nodes.Symlink) : baseIcon;
}
 
Example #23
Source File: IntelliUtils.java    From floobits-intellij with Apache License 2.0 4 votes vote down vote up
public static Boolean isSharable(VirtualFile virtualFile) {
    return (virtualFile != null  && virtualFile.isValid() && virtualFile.isInLocalFileSystem() && !virtualFile.is(VFileProperty.SPECIAL) && !virtualFile.is(VFileProperty.SYMLINK));
}
 
Example #24
Source File: FileImpl.java    From floobits-intellij with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isSymLink() {
    return virtualFile.is(VFileProperty.SYMLINK);
}
 
Example #25
Source File: PsiDirectoryIconDescriptorUpdater.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredReadAction
@Override
public void updateIcon(@Nonnull IconDescriptor iconDescriptor, @Nonnull PsiElement element, int flags) {
  if (element instanceof PsiDirectory) {
    PsiDirectory psiDirectory = (PsiDirectory)element;
    VirtualFile virtualFile = psiDirectory.getVirtualFile();

    Image symbolIcon;
    if (virtualFile.getFileSystem() instanceof ArchiveFileSystem) {
      if (virtualFile.getParent() == null) {
        symbolIcon = AllIcons.Nodes.PpJar;
      }
      else {
        PsiPackage psiPackage = myPsiPackageManager.findAnyPackage(virtualFile);
        symbolIcon = psiPackage != null ? AllIcons.Nodes.Package : AllIcons.Nodes.TreeClosed;
      }
    }
    else if (ProjectRootsUtil.isModuleContentRoot(myProjectFileIndex, virtualFile)) {
      symbolIcon = AllIcons.Nodes.Module;
    }
    else {
      boolean ignored = myProjectRootManager.getFileIndex().isExcluded(virtualFile);
      if (ignored) {
        symbolIcon = AllIcons.Modules.ExcludeRoot;
      }
      else {
        ContentFolder contentFolder = ProjectRootsUtil.findContentFolderForDirectory(myProjectFileIndex, virtualFile);
        if (contentFolder != null) {
          symbolIcon = contentFolder.getType().getIcon(contentFolder.getProperties());
        }
        else {
          ContentFolderTypeProvider contentFolderTypeForFile = myProjectFileIndex.getContentFolderTypeForFile(virtualFile);
          symbolIcon = contentFolderTypeForFile != null ? contentFolderTypeForFile.getChildDirectoryIcon(psiDirectory, myPsiPackageManager) : AllIcons.Nodes.TreeClosed;
        }
      }
    }

    if (symbolIcon != null) {
      iconDescriptor.setMainIcon(symbolIcon);
    }

    if (virtualFile.is(VFileProperty.SYMLINK)) {
      iconDescriptor.addLayerIcon(AllIcons.Nodes.Symlink);
    }
  }
  else if (element instanceof PsiPackage) {
    iconDescriptor.setMainIcon(AllIcons.Nodes.Package);
  }
}
 
Example #26
Source File: FileImpl.java    From floobits-intellij with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isSpecial() {
    return virtualFile.is(VFileProperty.SPECIAL);
}
 
Example #27
Source File: GoToLinkTargetAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  Project project = getEventProject(e);
  VirtualFile file = e.getDataContext().getData(CommonDataKeys.VIRTUAL_FILE);
  e.getPresentation().setEnabledAndVisible(project != null && file != null && file.is(VFileProperty.SYMLINK));
}
 
Example #28
Source File: FileContentQueue.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean isValidFile(@Nonnull VirtualFile file) {
  return file.isValid() && !file.isDirectory() && !file.is(VFileProperty.SPECIAL) && !VfsUtilCore.isBrokenLink(file);
}
 
Example #29
Source File: VirtualFileCellRenderer.java    From intellij-reference-diagram with Apache License 2.0 4 votes vote down vote up
private static Icon dressIcon(final VirtualFile file, final Icon baseIcon) {
    return file.isValid() && file.is(VFileProperty.SYMLINK) ? new LayeredIcon(baseIcon, PlatformIcons.SYMLINK_ICON) : baseIcon;
}
 
Example #30
Source File: FileElement.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isFileHidden(@Nullable VirtualFile file) {
  return file != null &&
         file.isValid() &&
         file.isInLocalFileSystem() &&
         (file.is(VFileProperty.HIDDEN) || SystemInfo.isUnix && file.getName().startsWith("."));
}