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

The following examples show how to use com.intellij.openapi.vfs.VirtualFile#is() . 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: 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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 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: 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 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: 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 14
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("."));
}
 
Example 15
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 16
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 17
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 18
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 19
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 20
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);
  }
}