Java Code Examples for com.intellij.openapi.util.Pair#empty()

The following examples show how to use com.intellij.openapi.util.Pair#empty() . 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: ArtifactCompilerUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static Pair<InputStream, Long> getArchiveEntryInputStream(VirtualFile sourceFile, final CompileContext context) throws IOException {
  final String fullPath = sourceFile.getPath();
  final int jarEnd = fullPath.indexOf(ArchiveFileSystem.ARCHIVE_SEPARATOR);
  LOG.assertTrue(jarEnd != -1, fullPath);
  String pathInJar = fullPath.substring(jarEnd + ArchiveFileSystem.ARCHIVE_SEPARATOR.length());
  String jarPath = fullPath.substring(0, jarEnd);
  final ZipFile jarFile = new ZipFile(new File(FileUtil.toSystemDependentName(jarPath)));
  final ZipEntry entry = jarFile.getEntry(pathInJar);
  if (entry == null) {
    context.addMessage(CompilerMessageCategory.ERROR, "Cannot extract '" + pathInJar + "' from '" + jarFile.getName() + "': entry not found", null, -1, -1);
    return Pair.empty();
  }

  BufferedInputStream bufferedInputStream = new BufferedInputStream(jarFile.getInputStream(entry)) {
    @Override
    public void close() throws IOException {
      super.close();
      jarFile.close();
    }
  };
  return Pair.<InputStream, Long>create(bufferedInputStream, entry.getSize());
}
 
Example 2
Source File: TabbedShowHistoryAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static Pair<FilePath, VirtualFile> getPathAndParentFile(@Nonnull VcsContext context) {
  if (context.getSelectedFilesStream().findAny().isPresent()) {
    VirtualFile file = getIfSingle(context.getSelectedFilesStream());
    return file != null ? Pair.create(VcsUtil.getFilePath(file), file) : Pair.empty();
  }

  File[] ioFiles = context.getSelectedIOFiles();
  if (ioFiles != null && ioFiles.length > 0) {
    for (File ioFile : ioFiles) {
      VirtualFile parent = getParentVirtualFile(ioFile);
      if (parent != null) return Pair.create(VcsUtil.getFilePath(parent, ioFile.getName()), parent);
    }
  }

  return Pair.empty();
}
 
Example 3
Source File: VcsLogClassicFilterUi.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Pair<VcsLogTextFilter, VcsLogHashFilter> getFiltersFromTextArea(@Nullable VcsLogTextFilter filter,
                                                                               boolean isRegexAllowed,
                                                                               boolean matchesCase) {
  if (filter == null) {
    return Pair.empty();
  }
  String text = filter.getText().trim();
  if (StringUtil.isEmptyOrSpaces(text)) {
    return Pair.empty();
  }
  List<String> hashes = ContainerUtil.newArrayList();
  for (String word : StringUtil.split(text, " ")) {
    if (!StringUtil.isEmptyOrSpaces(word) && word.matches(HASH_PATTERN)) {
      hashes.add(word);
    }
    else {
      break;
    }
  }

  VcsLogTextFilter textFilter;
  VcsLogHashFilterImpl hashFilter;
  if (!hashes.isEmpty()) { // text is ignored if there are hashes in the text
    textFilter = null;
    hashFilter = new VcsLogHashFilterImpl(hashes);
  }
  else {
    textFilter = new VcsLogTextFilterImpl(text, isRegexAllowed, matchesCase);
    hashFilter = null;
  }
  return Pair.<VcsLogTextFilter, VcsLogHashFilter>create(textFilter, hashFilter);
}
 
Example 4
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);
}