com.intellij.util.NotNullFunction Java Examples

The following examples show how to use com.intellij.util.NotNullFunction. 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: ExecutionHelper.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static Collection<RunContentDescriptor> findRunningConsole(final Project project,
                                                                  @Nonnull final NotNullFunction<RunContentDescriptor, Boolean> descriptorMatcher) {
  final ExecutionManager executionManager = ExecutionManager.getInstance(project);

  final RunContentDescriptor selectedContent = executionManager.getContentManager().getSelectedContent();
  if (selectedContent != null) {
    final ToolWindow toolWindow = ExecutionManager.getInstance(project).getContentManager().getToolWindowByDescriptor(selectedContent);
    if (toolWindow != null && toolWindow.isVisible()) {
      if (descriptorMatcher.fun(selectedContent)) {
        return Collections.singletonList(selectedContent);
      }
    }
  }

  final ArrayList<RunContentDescriptor> result = ContainerUtil.newArrayList();
  for (RunContentDescriptor runContentDescriptor : executionManager.getContentManager().getAllDescriptors()) {
    if (descriptorMatcher.fun(runContentDescriptor)) {
      result.add(runContentDescriptor);
    }
  }
  return result;
}
 
Example #2
Source File: RunIdeConsoleAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  List<String> languages = IdeScriptEngineManager.getInstance().getLanguages();
  if (languages.size() == 1) {
    runConsole(e, languages.iterator().next());
    return;
  }

  DefaultActionGroup actions =
          new DefaultActionGroup(ContainerUtil.map(languages, (NotNullFunction<String, AnAction>)language -> new DumbAwareAction(language) {
            @Override
            public void actionPerformed(@Nonnull AnActionEvent e1) {
              runConsole(e1, language);
            }
          }));
  JBPopupFactory.getInstance().createActionGroupPopup("Script Engine", actions, e.getDataContext(), JBPopupFactory.ActionSelectionAid.NUMBERING, false).
          showInBestPositionFor(e.getDataContext());
}
 
Example #3
Source File: PrintElementManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
PrintElementManagerImpl(@Nonnull final LinearGraph linearGraph,
                        @Nonnull final PermanentGraphInfo myPermanentGraph,
                        @Nonnull GraphColorManager colorManager) {
  myLinearGraph = linearGraph;
  myColorGetter = new ColorGetterByLayoutIndex(linearGraph, myPermanentGraph, colorManager);
  myGraphElementComparator = new GraphElementComparatorByLayoutIndex(new NotNullFunction<Integer, Integer>() {
    @Nonnull
    @Override
    public Integer fun(Integer nodeIndex) {
      int nodeId = linearGraph.getNodeId(nodeIndex);
      if (nodeId < 0) return nodeId;
      return myPermanentGraph.getPermanentGraphLayout().getLayoutIndex(nodeId);
    }
  });
}
 
Example #4
Source File: LoadTextUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static FileType processTextFromBinaryPresentationOrNull(@Nonnull byte[] bytes, int length,
                                                               @Nonnull VirtualFile virtualFile,
                                                               boolean saveDetectedSeparators,
                                                               boolean saveBOM,
                                                               @Nonnull FileType fileType,
                                                               @Nonnull NotNullFunction<? super CharSequence, ? extends FileType> fileTextProcessor) {
  DetectResult info = detectInternalCharsetAndSetBOM(virtualFile, bytes, length, saveBOM, fileType);
  Charset internalCharset = info.hardCodedCharset;
  CharsetToolkit.GuessedEncoding guessed = info.guessed;
  CharSequence toProcess;
  if (internalCharset == null || guessed == CharsetToolkit.GuessedEncoding.BINARY || guessed == CharsetToolkit.GuessedEncoding.INVALID_UTF8) {
    // the charset was not detected so the file is likely binary
    toProcess = null;
  }
  else {
    byte[] bom = info.BOM;
    int BOMEndOffset = Math.min(length, bom == null ? 0 : bom.length);
    ConvertResult result = convertBytes(bytes, BOMEndOffset, length, internalCharset);
    if (saveDetectedSeparators) {
      virtualFile.setDetectedLineSeparator(result.lineSeparator);
    }
    toProcess = result.text;
  }
  return fileTextProcessor.fun(toProcess);
}
 
Example #5
Source File: CommittedChangesCache.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean hasCachesWithEmptiness(final boolean emptiness) {
  final Ref<Boolean> resultRef = new Ref<Boolean>(Boolean.FALSE);
  myCachesHolder.iterateAllCaches(new NotNullFunction<ChangesCacheFile, Boolean>() {
    @Override
    @Nonnull
    public Boolean fun(final ChangesCacheFile changesCacheFile) {
      try {
        if (changesCacheFile.isEmpty() == emptiness) {
          resultRef.set(true);
          return true;
        }
      }
      catch (IOException e) {
        LOG.info(e);
      }
      return false;
    }
  });
  return resultRef.get();
}
 
Example #6
Source File: CachesHolder.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void iterateAllCaches(final NotNullFunction<ChangesCacheFile, Boolean> consumer) {
  final AbstractVcs[] vcses = myPlManager.getAllActiveVcss();
  for (AbstractVcs vcs : vcses) {
    final CommittedChangesProvider provider = vcs.getCommittedChangesProvider();
    if (provider instanceof CachingCommittedChangesProvider) {
      final Map<VirtualFile, RepositoryLocation> map = getAllRootsUnderVcs(vcs);
      for (VirtualFile root : map.keySet()) {
        final RepositoryLocation location = map.get(root);
        final ChangesCacheFile cacheFile = getCacheFile(vcs, root, location);
        if (Boolean.TRUE.equals(consumer.fun(cacheFile))) {
          return;
        }
      }
    }
  }
}
 
Example #7
Source File: PermanentLinearGraphBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public PermanentLinearGraphImpl build() {
  return build(new NotNullFunction<CommitId, Integer>() {
    @Nonnull
    @Override
    public Integer fun(CommitId dom) {
      return Integer.MIN_VALUE;
    }
  });
}
 
Example #8
Source File: CSharpResolveContextUtil.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static <T extends PsiElement> CSharpResolveContext cacheSimple(@Nonnull final T element, final NotNullFunction<T, CSharpResolveContext> fun)
{
	CachedValue<CSharpResolveContext> provider = element.getUserData(RESOLVE_CONTEXT);
	if(provider != null)
	{
		return provider.getValue();
	}

	CachedValue<CSharpResolveContext> cachedValue = CachedValuesManager.getManager(element.getProject()).createCachedValue(() -> CachedValueProvider.Result.create(fun.fun(element),
			PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT), false);
	element.putUserData(RESOLVE_CONTEXT, cachedValue);
	return cachedValue.getValue();
}
 
Example #9
Source File: SimpleGraphInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
private SimpleGraphInfo(@Nonnull LinearGraph linearGraph,
                        @Nonnull GraphLayout graphLayout,
                        @Nonnull NotNullFunction<Integer, CommitId> function,
                        @Nonnull TimestampGetter timestampGetter,
                        @Nonnull Set<Integer> branchNodeIds) {
  myLinearGraph = linearGraph;
  myGraphLayout = graphLayout;
  myFunction = function;
  myTimestampGetter = timestampGetter;
  myBranchNodeIds = branchNodeIds;
}
 
Example #10
Source File: SimpleGraphInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static <CommitId> NotNullFunction<Integer, CommitId> createCommitIdMapFunction(List<CommitId> commitsIdMap) {
  NotNullFunction<Integer, CommitId> function;
  if (!commitsIdMap.isEmpty() && commitsIdMap.get(0) instanceof Integer) {
    int[] ints = new int[commitsIdMap.size()];
    for (int row = 0; row < commitsIdMap.size(); row++) {
      ints[row] = (Integer)commitsIdMap.get(row);
    }
    function = (NotNullFunction<Integer, CommitId>)new IntegerCommitIdMapFunction(CompressedIntList.newInstance(ints));
  }
  else {
    function = new CommitIdMapFunction<>(commitsIdMap);
  }
  return function;
}
 
Example #11
Source File: CodeEditUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Allows to answer if given node is configured to be reformatted.
 *
 * @param node node to check
 * @return {@code true} if given node is configured to be reformatted; {@code false} otherwise
 */
public static boolean isMarkedToReformat(final ASTNode node) {
  if (node.getCopyableUserData(REFORMAT_KEY) == null || !isSuspendedNodesReformattingAllowed()) {
    return false;
  }
  final NotNullFunction<ASTNode, Boolean> strategy = NODE_REFORMAT_STRATEGY.get();
  return strategy == null || strategy.fun(node);
}
 
Example #12
Source File: XValueNodePresentationConfigurator.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void setPresentation(@Nullable Image icon,
                                   @NonNls @Nullable String type,
                                   @NonNls @Nonnull String value,
                                   @Nullable NotNullFunction<String, String> valuePresenter,
                                   boolean hasChildren, ConfigurableXValueNode node) {
  doSetPresentation(icon,
                    valuePresenter == null ? new XRegularValuePresentation(value, type) : new XValuePresentationAdapter(value, type, valuePresenter),
                    hasChildren, node);
}
 
Example #13
Source File: ObjectsConvertor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static <T,U, S extends U> List<S> convert(@Nonnull final Collection<T> in, final Convertor<T,S> convertor,
                                                 @Nullable final NotNullFunction<U, Boolean> outFilter) {
  final List<S> out = new ArrayList<S>();
  for (T t : in) {
    final S converted = convertor.convert(t);
    if ((outFilter != null) && (! Boolean.TRUE.equals(outFilter.fun(converted)))) continue;
    out.add(converted);
  }
  return out;
}
 
Example #14
Source File: CachesHolder.java    From consulo with Apache License 2.0 5 votes vote down vote up
public List<ChangesCacheFile> getAllCaches() {
  final List<ChangesCacheFile> result = new ArrayList<ChangesCacheFile>();
  iterateAllCaches(new NotNullFunction<ChangesCacheFile, Boolean>() {
    @Nonnull
    public Boolean fun(final ChangesCacheFile changesCacheFile) {
      result.add(changesCacheFile);
      return false;
    }
  });
  return result;
}
 
Example #15
Source File: ChangesViewContentManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void loadExtensionTabs() {
  final List<Content> contentList = new LinkedList<>();
  final ChangesViewContentEP[] contentEPs = myProject.getExtensions(ChangesViewContentEP.EP_NAME);
  for(ChangesViewContentEP ep: contentEPs) {
    final NotNullFunction<Project,Boolean> predicate = ep.newPredicateInstance(myProject);
    if (predicate == null || predicate.fun(myProject).equals(Boolean.TRUE)) {
      final Content content = ContentFactory.getInstance().createContent(new ContentStub(ep), ep.getTabName(), false);
      content.setCloseable(false);
      content.putUserData(myEPKey, ep);
      contentList.add(content);
    }
  }
  myAddedContents.addAll(0, contentList);
}
 
Example #16
Source File: ChangesViewContentManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void updateExtensionTabs() {
  final ChangesViewContentEP[] contentEPs = myProject.getExtensions(ChangesViewContentEP.EP_NAME);
  for(ChangesViewContentEP ep: contentEPs) {
    final NotNullFunction<Project,Boolean> predicate = ep.newPredicateInstance(myProject);
    if (predicate == null) continue;
    Content epContent = findEPContent(ep);
    final Boolean predicateResult = predicate.fun(myProject);
    if (predicateResult.equals(Boolean.TRUE) && epContent == null) {
      addExtensionTab(ep);
    }
    else if (predicateResult.equals(Boolean.FALSE) && epContent != null) {
      myContentManager.removeContent(epContent, true);
    }
  }
}
 
Example #17
Source File: VcsContextFactoryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public FilePath createFilePathOn(@Nonnull final File file, @Nonnull final NotNullFunction<File, Boolean> detector) {
  VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(file);
  if (virtualFile != null) {
    return createFilePathOn(virtualFile);
  }
  return createFilePathOn(file, detector.fun(file).booleanValue());
}
 
Example #18
Source File: NavigationGutterIconBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected NavigationGutterIconBuilder(@Nonnull final Image icon,
                                      @Nonnull NotNullFunction<T, Collection<? extends PsiElement>> converter,
                                      final @Nullable NotNullFunction<T, Collection<? extends GotoRelatedItem>> gotoRelatedItemProvider) {
  myIcon = icon;
  myConverter = converter;
  myGotoRelatedItemProvider = gotoRelatedItemProvider;
}
 
Example #19
Source File: ExecutionHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static Collection<RunContentDescriptor> findRunningConsoleByTitle(final Project project,
                                                                         @Nonnull final NotNullFunction<String, Boolean> titleMatcher) {
  return findRunningConsole(project, new NotNullFunction<RunContentDescriptor, Boolean>() {
    @Nonnull
    @Override
    public Boolean fun(RunContentDescriptor selectedContent) {
      return titleMatcher.fun(selectedContent.getDisplayName());
    }
  });
}
 
Example #20
Source File: ExecutionHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static List<RunContentDescriptor> collectConsolesByDisplayName(final Project project, @Nonnull NotNullFunction<String, Boolean> titleMatcher) {
  List<RunContentDescriptor> result = ContainerUtil.newArrayList();
  final ExecutionManager executionManager = ExecutionManager.getInstance(project);
  for (RunContentDescriptor runContentDescriptor : executionManager.getContentManager().getAllDescriptors()) {
    if (titleMatcher.fun(runContentDescriptor.getDisplayName())) {
      result.add(runContentDescriptor);
    }
  }
  return result;
}
 
Example #21
Source File: IntroduceTargetChooser.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static <T extends PsiElement> void showChooser(final Editor editor,
                                                      final List<T> expressions,
                                                      final Pass<T> callback,
                                                      final Function<T, String> renderer,
                                                      String title,
                                                      NotNullFunction<PsiElement, TextRange> ranger) {
  showChooser(editor, expressions, callback, renderer, title, -1, ranger);
}
 
Example #22
Source File: VcsLogRefresherImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private GraphCommitImpl<Integer> compactCommit(@Nonnull TimedVcsCommit commit, @Nonnull final VirtualFile root) {
  List<Integer> parents = ContainerUtil.map(commit.getParents(),
                                            (NotNullFunction<Hash, Integer>)hash -> myHashMap.getCommitIndex(hash, root));
  int index = myHashMap.getCommitIndex(commit.getId(), root);
  myIndex.markForIndexing(index, root);
  return new GraphCommitImpl<>(index, parents, commit.getTimestamp());
}
 
Example #23
Source File: MockVcsContextFactory.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@Deprecated
@NotNull
//@Override
public FilePath createFilePathOn(@NotNull File file, @NotNull NotNullFunction<File, Boolean> notNullFunction) {
    return new IOFilePath(file,
            file.exists() ? file.isDirectory() :
                    notNullFunction.fun(file)
    );
}
 
Example #24
Source File: CSharpTypeRefCacher.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredReadAction
public DotNetTypeRef toTypeRef(E element, boolean resolveFromParentOrInitializer)
{
	if(CSharpReferenceExpressionImplUtil.isCacheDisabled(element))
	{
		return toTypeRefImpl(element, resolveFromParentOrInitializer);
	}

	Key<CachedValue<DotNetTypeRef>> key = resolveFromParentOrInitializer ? ourTrueTypeRefKey : ourFalseTypeRefKey;
	NotNullFunction<E, DotNetTypeRef> resolver = resolveFromParentOrInitializer ? myTrueFunction : myFalseFunction;
	return myLocal ? DotNetTypeRefCacheUtil.localCacheTypeRef(key, element, resolver) : DotNetTypeRefCacheUtil.cacheTypeRef(key, element, resolver);
}
 
Example #25
Source File: CSharpTypeRefCacher.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredReadAction
public DotNetTypeRef toTypeRef(E element, boolean resolveFromParentOrInitializer, Object... dropKeys)
{
	if(CSharpReferenceExpressionImplUtil.isCacheDisabled(element))
	{
		return toTypeRefImpl(element, resolveFromParentOrInitializer);
	}

	Key<CachedValue<DotNetTypeRef>> key = resolveFromParentOrInitializer ? ourTrueTypeRefKey : ourFalseTypeRefKey;
	NotNullFunction<E, DotNetTypeRef> resolver = resolveFromParentOrInitializer ? myTrueFunction : myFalseFunction;
	return DotNetTypeRefCacheUtil.cacheTypeRef(key, element, resolver, dropKeys);
}
 
Example #26
Source File: JBLoadingPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public JBLoadingPanel(@Nullable LayoutManager manager, @Nonnull NotNullFunction<? super JPanel, ? extends LoadingDecorator> createLoadingDecorator) {
  super(new BorderLayout());
  myPanel = manager == null ? new JPanel() : new JPanel(manager);
  myPanel.setOpaque(false);
  myPanel.setFocusable(false);
  myDecorator = createLoadingDecorator.fun(myPanel);
  super.add(myDecorator.getComponent(), BorderLayout.CENTER);
}
 
Example #27
Source File: PermanentLinearGraphBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public PermanentLinearGraphImpl build(@Nonnull NotNullFunction<CommitId, Integer> notLoadedCommitToId) {
  for (int nodeIndex = 0; nodeIndex < myNodesCount; nodeIndex++) {
    doStep(nodeIndex);
  }

  fixUnderdoneEdges(notLoadedCommitToId);

  return new PermanentLinearGraphImpl(mySimpleNodes, myNodeToEdgeIndex, myLongEdges);
}
 
Example #28
Source File: StructureFilterPopupComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static <F> String getTooltipTextForFiles(@Nonnull Collection<F> files,
                                                 @Nonnull Comparator<F> comparator,
                                                 @Nonnull NotNullFunction<F, String> getText) {
  List<F> filesToDisplay = ContainerUtil.sorted(files, comparator);
  if (files.size() > 10) {
    filesToDisplay = filesToDisplay.subList(0, 10);
  }
  String tooltip = StringUtil.join(filesToDisplay, getText, "\n");
  if (files.size() > 10) {
    tooltip += "\n...";
  }
  return tooltip;
}
 
Example #29
Source File: PermanentLinearGraphBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void fixUnderdoneEdges(@Nonnull NotNullFunction<CommitId, Integer> notLoadedCommitToId) {
  List<CommitId> commitIds = ContainerUtil.newArrayList(upAdjacentNodes.keySet());
  ContainerUtil.sort(commitIds, new Comparator<CommitId>() {
    @Override
    public int compare(@Nonnull CommitId o1, @Nonnull CommitId o2) {
      return Collections.min(upAdjacentNodes.get(o1)) - Collections.min(upAdjacentNodes.get(o2));
    }
  });
  for (CommitId notLoadCommit : commitIds) {
    int notLoadId = notLoadedCommitToId.fun(notLoadCommit);
    for (int upNodeIndex : upAdjacentNodes.get(notLoadCommit)) {
      fixUnderdoneEdgeForNotLoadCommit(upNodeIndex, notLoadId);
    }
  }
}
 
Example #30
Source File: StatisticsManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public StatisticsInfo[] getAllValues(final String context) {
  final String[] strings;
  synchronized (LOCK) {
    strings = getUnit(getUnitNumber(context)).getKeys2(context);
  }
  return ContainerUtil.map2Array(strings, StatisticsInfo.class, (NotNullFunction<String, StatisticsInfo>)s -> new StatisticsInfo(context, s));
}