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

The following examples show how to use com.intellij.openapi.vfs.VirtualFile#isDirectory() . 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: SelectInTargetImpl.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean canSelect(@Nonnull final SelectInContext context) {
  if (this.myProject.isDisposed()) {
    return false;
  } else {
    VirtualFile virtualFile = context.getVirtualFile();
    if (!virtualFile.isValid()) {
      return false;
    } else {
      final Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
      Object psiFile;
      if (document != null) {
        psiFile = PsiDocumentManager.getInstance(this.myProject).getPsiFile(document);
      } else if (context.getSelectorInFile() instanceof PsiFile) {
        psiFile = context.getSelectorInFile();
      } else if (virtualFile.isDirectory()) {
        psiFile = PsiManager.getInstance(this.myProject).findDirectory(virtualFile);
      } else {
        psiFile = PsiManager.getInstance(this.myProject).findFile(virtualFile);
      }
      return psiFile != null;
    }
  }
}
 
Example 2
Source File: AnnotateVcsVirtualFileAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean isEnabled(AnActionEvent e) {
  Project project = e.getData(CommonDataKeys.PROJECT);
  if (project == null || project.isDisposed()) return false;

  VirtualFile[] selectedFiles = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
  if (selectedFiles == null || selectedFiles.length != 1) return false;

  VirtualFile file = selectedFiles[0];
  if (file.isDirectory() || file.getFileType().isBinary()) return false;

  if (VcsAnnotateUtil.getEditors(project, file).isEmpty()) return false;

  AnnotationData data = extractData(project, file);
  if (data == null) return false;

  AnnotationProvider provider = data.vcs.getAnnotationProvider();
  return provider instanceof AnnotationProviderEx;
}
 
Example 3
Source File: ContentEntryEditingAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  super.update(e);
  final Presentation presentation = e.getPresentation();
  presentation.setEnabled(true);
  final VirtualFile[] files = getSelectedFiles();
  if (files.length == 0) {
    presentation.setEnabled(false);
    return;
  }
  for (VirtualFile file : files) {
    if (file == null || !file.isDirectory()) {
      presentation.setEnabled(false);
      break;
    }
  }
}
 
Example 4
Source File: VcsDescriptor.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean probablyUnderVcs(final VirtualFile file) {
  if (file == null || (! file.isDirectory()) || (! file.isValid())) return false;
  if (myAdministrativePattern == null) return false;
  return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
    @Override
    public Boolean compute() {
      if (checkFileForBeingAdministrative(file)) return true;
      if (myCrawlUpToCheckUnderVcs) {
        VirtualFile current = file.getParent();
        while (current != null) {
          if (checkFileForBeingAdministrative(current)) return true;
          current = current.getParent();
        }
      }
      return false;
    }
  });
}
 
Example 5
Source File: PubRoot.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns true if the given file is a directory that contains tests.
 */
public boolean hasTests(@NotNull VirtualFile dir) {
  if (!dir.isDirectory()) return false;

  // We can run tests in the pub root. (It will look in the test dir.)
  if (getRoot().equals(dir)) return true;

  // Any directory in the test dir or below is also okay.
  final VirtualFile wanted = getTestDir();
  if (wanted == null) return false;

  while (dir != null) {
    if (wanted.equals(dir)) return true;
    dir = dir.getParent();
  }
  return false;
}
 
Example 6
Source File: ProtoFileRelativePathRootsProvider.java    From protobuf-jetbrains-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public VirtualFile[] getSourceRoots(Module module, @Nullable ProtoPsiFileRoot psiFileRoot) {
    if (psiFileRoot != null) {
        VirtualFile file = psiFileRoot.getVirtualFile();
        if (file != null) {
            VirtualFile dir = file;
            List<VirtualFile> result = new ArrayList<>();
            for (int i = 0; i < MAX_NESTING_LEVEL; i++) {
                try {
                    dir = dir.getParent();
                    if (dir != null && dir.isDirectory()) {
                        result.add(dir);
                    } else {
                        break;
                    }
                } catch (Exception e) {
                    break;
                }
            }
            return result.toArray(new VirtualFile[0]);
        }
    }
    return NONE;
}
 
Example 7
Source File: ProtobufSettings.java    From protobuf-jetbrains-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Get a list of {@link VirtualFile} for include paths.
 */
@NotNull
public List<VirtualFile> getIncludePathsVf() {
    List<VirtualFile> result = new ArrayList<>();
    List<String> includePaths = getIncludePaths();
    for (String includePath : includePaths) {
        VirtualFile path = LocalFileSystem.getInstance().findFileByPath(includePath);
        if (path != null && path.isDirectory()) {
            result.add(path);
        }
    }
    return result;
}
 
Example 8
Source File: FileReference.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a wrapper like WebDirectoryElement into plain PsiFile
 */
protected static PsiFileSystemItem getOriginalFile(PsiFileSystemItem fileSystemItem) {
  final VirtualFile file = fileSystemItem.getVirtualFile();
  if (file != null && !file.isDirectory()) {
    final PsiManager psiManager = fileSystemItem.getManager();
    if (psiManager != null) {
      final PsiFile psiFile = psiManager.findFile(file);
      if (psiFile != null) {
        fileSystemItem = psiFile;
      }
    }
  }
  return fileSystemItem;
}
 
Example 9
Source File: PushedFilePropertiesUpdaterImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void filePropertiesChanged(@Nonnull VirtualFile fileOrDir, @Nonnull Condition<? super VirtualFile> acceptFileCondition) {
  if (fileOrDir.isDirectory()) {
    for (VirtualFile child : fileOrDir.getChildren()) {
      if (!child.isDirectory() && acceptFileCondition.value(child)) {
        filePropertiesChanged(child);
      }
    }
  }
  else if (acceptFileCondition.value(fileOrDir)) {
    filePropertiesChanged(fileOrDir);
  }
}
 
Example 10
Source File: LanguagePerFileConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean isValueEditableForFile(final VirtualFile virtualFile) {
  boolean enabled = true;
  if (virtualFile != null) {
    if (!virtualFile.isDirectory()) {
      final FileType fileType = virtualFile.getFileType();
      if (fileType.isBinary()) {
        enabled = false;
      }
    }
  }
  return enabled;
}
 
Example 11
Source File: Workspace.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns the closest WORKSPACE file within or above the given directory, or null if not found.
 */
@Nullable
private static VirtualFile findContainingWorkspaceFile(@NotNull VirtualFile dir) {
  while (dir != null) {
    final VirtualFile child = dir.findChild("WORKSPACE");
    if (child != null && child.exists() && !child.isDirectory()) {
      return child;
    }
    dir = dir.getParent();
  }

  // not found
  return null;
}
 
Example 12
Source File: WolfTheProblemSolverImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Problem convertToProblem(@Nullable final VirtualFile virtualFile, final int line, final int column, @Nonnull final String[] message) {
  if (virtualFile == null || virtualFile.isDirectory() || virtualFile.getFileType().isBinary()) return null;
  HighlightInfo info = ReadAction.compute(() -> {
    TextRange textRange = getTextRange(virtualFile, line, column);
    String description = StringUtil.join(message, "\n");
    return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description).create();
  });
  if (info == null) return null;
  return new ProblemImpl(virtualFile, info, false);
}
 
Example 13
Source File: MergeVersion.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void reportProjectFileChangeIfNeeded(Project project, VirtualFile file) {
  if (file != null && ! file.isDirectory()) {
    if (ProjectCoreUtil.isProjectOrWorkspaceFile(file) || isProjectFile(file)) {
      ProjectManagerEx.getInstanceEx().saveChangedProjectFile(file, project);
    }
  }
}
 
Example 14
Source File: VirtualFileHolder.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void removeFile(VirtualFile file) {
  if (myFiles.remove(file)) {
    if (file.isDirectory()) {
      -- myNumDirs;
    }
  }
}
 
Example 15
Source File: RootIndex.java    From consulo with Apache License 2.0 5 votes vote down vote up
boolean resetOnEvents(@Nonnull List<? extends VFileEvent> events) {
  for (VFileEvent event : events) {
    VirtualFile file = event.getFile();
    if (file == null || file.isDirectory()) {
      return true;
    }
  }
  return false;
}
 
Example 16
Source File: BlazeCustomHeaderProvider.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public VirtualFile getCustomHeaderFile(
    String includeString,
    HeaderSearchStage stage,
    @Nullable OCResolveConfiguration configuration) {
  if (stage != HeaderSearchStage.BEFORE_START
      || includeString.startsWith("/")
      || configuration == null) {
    return null;
  }
  Project project = configuration.getProject();
  BlazeProjectData data = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
  if (data == null) {
    return null;
  }
  WorkspacePathResolver workspacePathResolver = data.getWorkspacePathResolver();
  Optional<VirtualFile> workspaceRoot = getWorkspaceRoot(includeString, workspacePathResolver);
  if (!workspaceRoot.isPresent()) {
    return null;
  }
  VirtualFile file = workspaceRoot.get().findFileByRelativePath(includeString);
  if (file == null || file.isDirectory()) {
    return null;
  }
  return file;
}
 
Example 17
Source File: FilePathImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public FilePathImpl(@Nonnull VirtualFile virtualFile) {
  this(virtualFile.getParent(), virtualFile.getName(), virtualFile.isDirectory(), virtualFile, false);
}
 
Example 18
Source File: CreateFileAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredUIAccess
@Override
public boolean checkInput(String inputString) {
  final StringTokenizer tokenizer = new StringTokenizer(inputString, "\\/");
  VirtualFile vFile = getDirectory().getVirtualFile();
  boolean firstToken = true;
  while (tokenizer.hasMoreTokens()) {
    final String token = tokenizer.nextToken();
    if ((token.equals(".") || token.equals("..")) && !tokenizer.hasMoreTokens()) {
      myErrorText = "Can't create file with name '" + token + "'";
      return false;
    }
    if (vFile != null) {
      if (firstToken && "~".equals(token)) {
        final VirtualFile userHomeDir = VfsUtil.getUserHomeDir();
        if (userHomeDir == null) {
          myErrorText = "User home directory not found";
          return false;
        }
        vFile = userHomeDir;
      }
      else if ("..".equals(token)) {
        vFile = vFile.getParent();
        if (vFile == null) {
          myErrorText = "Not a valid directory";
          return false;
        }
      }
      else if (!".".equals(token)) {
        final VirtualFile child = vFile.findChild(token);
        if (child != null) {
          if (!child.isDirectory()) {
            myErrorText = "A file with name '" + token + "' already exists";
            return false;
          }
          else if (!tokenizer.hasMoreTokens()) {
            myErrorText = "A directory with name '" + token + "' already exists";
            return false;
          }
        }
        vFile = child;
      }
    }
    if (FileTypeManager.getInstance().isFileIgnored(getFileName(token))) {
      myErrorText = "'" + token + "' is an ignored name (Settings | Editor | File Types | Ignore files and folders)";
      return true;
    }
    firstToken = false;
  }
  myErrorText = null;
  return true;
}
 
Example 19
Source File: VirtualFileHolder.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void addFile(VirtualFile file) {
  myFiles.add(file);
  if (file.isDirectory()) ++ myNumDirs;
}
 
Example 20
Source File: OpenProjectFileChooserDescriptor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isFileVisible(final VirtualFile file, final boolean showHiddenFiles) {
  if (!showHiddenFiles && FileElement.isFileHidden(file)) return false;
  return canOpen(file) || super.isFileVisible(file, showHiddenFiles) && file.isDirectory();
}