Java Code Examples for com.intellij.util.containers.ContainerUtil#mapNotNull()

The following examples show how to use com.intellij.util.containers.ContainerUtil#mapNotNull() . 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: VcsRevisionNumberArrayRule.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public List<VcsRevisionNumber> getRevisionNumbers(@Nonnull DataProvider dataProvider) {
  VcsRevisionNumber revisionNumber = dataProvider.getDataUnchecked(VcsDataKeys.VCS_REVISION_NUMBER);
  if (revisionNumber != null) {
    return Collections.singletonList(revisionNumber);
  }

  ChangeList[] changeLists = dataProvider.getDataUnchecked(VcsDataKeys.CHANGE_LISTS);
  if (changeLists != null && changeLists.length > 0) {
    List<CommittedChangeList> committedChangeLists = ContainerUtil.findAll(changeLists, CommittedChangeList.class);

    if (!committedChangeLists.isEmpty()) {
      ContainerUtil.sort(committedChangeLists, CommittedChangeListByDateComparator.DESCENDING);

      return ContainerUtil.mapNotNull(committedChangeLists, CommittedChangeListToRevisionNumberFunction.INSTANCE);
    }
  }

  VcsFileRevision[] fileRevisions = dataProvider.getDataUnchecked(VcsDataKeys.VCS_FILE_REVISIONS);
  if (fileRevisions != null && fileRevisions.length > 0) {
    return ContainerUtil.mapNotNull(fileRevisions, FileRevisionToRevisionNumberFunction.INSTANCE);
  }

  return null;
}
 
Example 2
Source File: StructureFilterPopupComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  Project project = e.getRequiredData(CommonDataKeys.PROJECT);
  VcsLogDataPack dataPack = myFilterModel.getDataPack();
  VcsLogFileFilter filter = myFilterModel.getFilter();

  Collection<VirtualFile> files;
  if (filter == null || filter.getStructureFilter() == null) {
    files = Collections.emptySet();
  }
  else {
    files = ContainerUtil.mapNotNull(filter.getStructureFilter().getFiles(), filePath -> {
      // for now, ignoring non-existing paths
      return filePath.getVirtualFile();
    });
  }

  VcsStructureChooser chooser = new VcsStructureChooser(project, "Select Files or Folders to Filter by", files,
                                                        new ArrayList<>(dataPack.getLogProviders().keySet()));
  if (chooser.showAndGet()) {
    VcsLogStructureFilterImpl structureFilter = new VcsLogStructureFilterImpl(new HashSet<VirtualFile>(chooser.getSelectedFiles()));
    myFilterModel.setFilter(new VcsLogFileFilter(structureFilter, null));
    myHistory.add(structureFilter);
  }
}
 
Example 3
Source File: PushController.java    From consulo with Apache License 2.0 6 votes vote down vote up
private Collection<MyRepoModel<?, ?, ?>> getSelectedRepoNode() {
  if (mySingleRepoProject) {
    return myView2Model.values();
  }
  //return all selected despite a loading state;
  return ContainerUtil.mapNotNull(myView2Model.entrySet(),
                                  new Function<Map.Entry<RepositoryNode, MyRepoModel<?, ?, ?>>, MyRepoModel<?, ?, ?>>() {
                                    @Override
                                    public MyRepoModel fun(Map.Entry<RepositoryNode, MyRepoModel<?, ?, ?>> entry) {
                                      MyRepoModel<?, ?, ?> model = entry.getValue();
                                      return model.isSelected() &&
                                             model.getTarget() != null ? model :
                                             null;
                                    }
                                  });
}
 
Example 4
Source File: LinearGraphParser.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Example input line:
 * 0_U|-1_U 2_D
 */
public static Pair<Pair<Integer, GraphNode>, List<String>> parseLine(@Nonnull String line, int lineNumber) {
  int separatorIndex = nextSeparatorIndex(line, 0);
  Pair<Integer, Character> pair = parseNumberWithChar(line.substring(0, separatorIndex));

  GraphNode graphNode = new GraphNode(lineNumber, parseGraphNodeType(pair.second));

  String[] edges = line.substring(separatorIndex + 2).split("\\s");
  List<String> normalEdges = ContainerUtil.mapNotNull(edges, new Function<String, String>() {
    @javax.annotation.Nullable
    @Override
    public String fun(String s) {
      if (s.isEmpty()) return null;
      return s;
    }
  });
  return Pair.create(Pair.create(pair.first, graphNode), normalEdges);
}
 
Example 5
Source File: VfsEventGenerationHelper.java    From consulo with Apache License 2.0 6 votes vote down vote up
void scheduleCreation(@Nonnull VirtualFile parent,
                      @Nonnull String childName,
                      @Nonnull FileAttributes attributes,
                      @Nullable String symlinkTarget,
                      @Nonnull ThrowableRunnable<RefreshWorker.RefreshCancelledException> checkCanceled) throws RefreshWorker.RefreshCancelledException {
  if (LOG.isTraceEnabled()) LOG.trace("create parent=" + parent + " name=" + childName + " attr=" + attributes);
  ChildInfo[] children = null;
  if (attributes.isDirectory() && parent.getFileSystem() instanceof LocalFileSystem && !attributes.isSymLink()) {
    try {
      Path child = Paths.get(parent.getPath(), childName);
      if (shouldScanDirectory(parent, child, childName)) {
        Path[] relevantExcluded = ContainerUtil.mapNotNull(ProjectManagerEx.getInstanceEx().getAllExcludedUrls(), url -> {
          Path path = Paths.get(VirtualFileManager.extractPath(url));
          return path.startsWith(child) ? path : null;
        }, new Path[0]);
        children = scanChildren(child, relevantExcluded, checkCanceled);
      }
    }
    catch (InvalidPathException ignored) {
      // Paths.get() throws sometimes
    }
  }
  VFileCreateEvent event = new VFileCreateEvent(null, parent, childName, attributes.isDirectory(), attributes, symlinkTarget, true, children);
  myEvents.add(event);
}
 
Example 6
Source File: LinearGraphUtils.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static List<Integer> getDownNodesIncludeNotLoad(@Nonnull final LinearGraph graph, final int nodeIndex) {
  return ContainerUtil.mapNotNull(graph.getAdjacentEdges(nodeIndex, EdgeFilter.ALL), new Function<GraphEdge, Integer>() {
    @javax.annotation.Nullable
    @Override
    public Integer fun(GraphEdge graphEdge) {
      if (isEdgeDown(graphEdge, nodeIndex)) {
        if (graphEdge.getType() == GraphEdgeType.NOT_LOAD_COMMIT) return graphEdge.getTargetId();
        return graphEdge.getDownNodeIndex();
      }
      return null;
    }
  });
}
 
Example 7
Source File: MultilinePopupBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
List<String> getSelectedValues() {
  return ContainerUtil.mapNotNull(StringUtil.tokenize(myTextField.getText(), new String(SEPARATORS)), value -> {
    String trimmed = value.trim();
    return trimmed.isEmpty() ? null : trimmed;
  });
}
 
Example 8
Source File: FileChooserUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static List<VirtualFile> getChosenFiles(@Nonnull final FileChooserDescriptor descriptor,
                                               @Nonnull final Collection<VirtualFile> selectedFiles) {
  return ContainerUtil.mapNotNull(selectedFiles, new NullableFunction<VirtualFile, VirtualFile>() {
    @Override
    public VirtualFile fun(final VirtualFile file) {
      return file != null && file.isValid() ? descriptor.getFileToSelect(file) : null;
    }
  });
}
 
Example 9
Source File: UsageInfoToUsageConverter.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static List<SmartPsiElementPointer<PsiElement>> convertToSmartPointers(@Nonnull PsiElement[] primaryElements) {
  if (primaryElements.length == 0) return Collections.emptyList();

  final SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(primaryElements[0].getProject());
  return ContainerUtil.mapNotNull(primaryElements, new Function<PsiElement, SmartPsiElementPointer<PsiElement>>() {
    @Override
    public SmartPsiElementPointer<PsiElement> fun(final PsiElement s) {
      return smartPointerManager.createSmartPsiElementPointer(s);
    }
  });
}
 
Example 10
Source File: ElmModuleIndex.java    From elm-plugin with MIT License 5 votes vote down vote up
@NotNull
private static List<ElmFile> getFilesByModuleName(@NotNull String moduleName, @NotNull Project project, @NotNull GlobalSearchScope searchScope) {
    final PsiManager psiManager = PsiManager.getInstance(project);
    Collection<VirtualFile> virtualFiles = getVirtualFilesByModuleName(moduleName, searchScope);
    return ContainerUtil.mapNotNull(virtualFiles, virtualFile -> {
        final PsiFile psiFile = psiManager.findFile(virtualFile);
        return psiFile instanceof ElmFile ? (ElmFile)psiFile : null;
    });
}
 
Example 11
Source File: TextDiffViewerUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static <T> boolean areEqualDocumentContentProperties(@Nonnull List<? extends DiffContent> contents,
                                                             @Nonnull final Function<DocumentContent, T> propertyGetter) {
  List<T> properties = ContainerUtil.mapNotNull(contents, new Function<DiffContent, T>() {
    @Override
    public T fun(DiffContent content) {
      if (content instanceof EmptyContent) return null;
      return propertyGetter.fun((DocumentContent)content);
    }
  });

  if (properties.size() < 2) return true;
  return ContainerUtil.newHashSet(properties).size() == 1;
}
 
Example 12
Source File: ColorPickerListenerFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static ColorPickerListener[] createListenersFor(@Nullable final PsiElement element) {
  final List<ColorPickerListener> listeners =
    ContainerUtil.mapNotNull(EP_NAME.getExtensions(), new Function<ColorPickerListenerFactory, ColorPickerListener>() {
      @Override
      public ColorPickerListener fun(ColorPickerListenerFactory factory) {
        return factory.createListener(element);
      }
    });
  return listeners.toArray(new ColorPickerListener[listeners.size()]);
}
 
Example 13
Source File: DvcsUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static List<VirtualFile> findVirtualFilesWithRefresh(@Nonnull List<File> files) {
  RefreshVFsSynchronously.refreshFiles(files);
  return ContainerUtil.mapNotNull(files, new Function<File, VirtualFile>() {
    @Override
    public VirtualFile fun(File file) {
      return VfsUtil.findFileByIoFile(file, false);
    }
  });
}
 
Example 14
Source File: VcsDirectoryConfigurationPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private List<VcsDirectoryMapping> getModelMappings() {
  return ContainerUtil.mapNotNull(myModel.getItems(), new Function<MapInfo, VcsDirectoryMapping>() {
    @Override
    public VcsDirectoryMapping fun(MapInfo info) {
      return info == MapInfo.SEPARATOR || info.type == MapInfo.Type.UNREGISTERED ? null : info.mapping;
    }
  });
}
 
Example 15
Source File: LinearGraphUtils.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static List<Integer> getUpNodes(@Nonnull LinearGraph graph, final int nodeIndex) {
  return ContainerUtil.mapNotNull(graph.getAdjacentEdges(nodeIndex, EdgeFilter.NORMAL_UP), new Function<GraphEdge, Integer>() {
    @javax.annotation.Nullable
    @Override
    public Integer fun(GraphEdge graphEdge) {
      return graphEdge.getUpNodeIndex();
    }
  });
}
 
Example 16
Source File: LinearGraphUtils.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static List<Integer> getDownNodes(@Nonnull LinearGraph graph, final int nodeIndex) {
  return ContainerUtil.mapNotNull(graph.getAdjacentEdges(nodeIndex, EdgeFilter.NORMAL_DOWN), new Function<GraphEdge, Integer>() {
    @javax.annotation.Nullable
    @Override
    public Integer fun(GraphEdge graphEdge) {
      return graphEdge.getDownNodeIndex();
    }
  });
}
 
Example 17
Source File: CopyReferenceAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static List<PsiElement> getElementsToCopy(@Nullable final Editor editor, final DataContext dataContext) {
  List<PsiElement> elements = ContainerUtil.newArrayList();
  if (editor != null) {
    PsiReference reference = TargetElementUtil.findReference(editor);
    if (reference != null) {
      ContainerUtil.addIfNotNull(elements, reference.getElement());
    }
  }

  if (elements.isEmpty()) {
    ContainerUtil.addIfNotNull(elements, dataContext.getData(CommonDataKeys.PSI_ELEMENT));
  }

  if (elements.isEmpty() && editor == null) {
    final Project project = dataContext.getData(CommonDataKeys.PROJECT);
    VirtualFile[] files = dataContext.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    if (project != null && files != null) {
      for (VirtualFile file : files) {
        ContainerUtil.addIfNotNull(elements, PsiManager.getInstance(project).findFile(file));
      }
    }
  }

  return ContainerUtil.mapNotNull(elements, new Function<PsiElement, PsiElement>() {
    @Override
    public PsiElement fun(PsiElement element) {
      return element instanceof PsiFile && !((PsiFile)element).getViewProvider().isPhysical() ? null : adjustElement(element);
    }
  });
}
 
Example 18
Source File: FileReferenceSet.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
protected Collection<PsiFileSystemItem> toFileSystemItems(@Nonnull Collection<VirtualFile> files) {
  final PsiManager manager = getElement().getManager();
  return ContainerUtil.mapNotNull(files, (NullableFunction<VirtualFile, PsiFileSystemItem>)file -> file != null ? manager.findDirectory(file) : null);
}
 
Example 19
Source File: VisiblePackBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
private Set<Integer> getMatchingHeads(@Nonnull VcsLogRefs refs, @Nonnull final VcsLogBranchFilter filter) {
  return new HashSet<>(ContainerUtil.mapNotNull(refs.getBranches(), ref -> {
    boolean acceptRef = filter.matches(ref.getName());
    return acceptRef ? myHashMap.getCommitIndex(ref.getCommitHash(), ref.getRoot()) : null;
  }));
}
 
Example 20
Source File: CommitChangeListDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Collection<VirtualFile> getVirtualFiles() {
  return ContainerUtil.mapNotNull(getIncludedChanges(), (change) -> ChangesUtil.getFilePath(change).getVirtualFile());
}