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

The following examples show how to use com.intellij.openapi.vfs.VirtualFile#is() . 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
Source Project: consulo   File: FileChooserDescriptor.java    License: 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 3
Source Project: consulo   File: PsiFileNode.java    License: 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 4
@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
@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 Project: consulo   File: AbstractPsiBasedNode.java    License: 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 7
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 8
Source Project: consulo   File: FileChooserDescriptor.java    License: 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 9
Source Project: consulo   File: FileTypeManagerImpl.java    License: 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 10
@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 11
Source Project: consulo   File: EditSourceUtil.java    License: 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 12
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 13
Source Project: consulo   File: NavBarPanel.java    License: 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 14
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 15
Source Project: floobits-intellij   File: IntelliUtils.java    License: 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 16
Source Project: consulo   File: FileElement.java    License: 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 17
Source Project: consulo   File: FileContentQueue.java    License: 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 18
Source Project: consulo   File: FileStatusManagerImpl.java    License: 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 19
Source Project: consulo   File: PsiUtilBase.java    License: 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 20
@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);
  }
}