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

The following examples show how to use com.intellij.util.containers.ContainerUtil#findAll() . 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: AttributeByNameSelector.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public Collection<PsiElement> doSelectElement(@Nonnull CSharpResolveContext context, boolean deep)
{
	if(myNameWithAt.isEmpty())
	{
		return Collections.emptyList();
	}

	UserDataHolderBase options = new UserDataHolderBase();
	options.putUserData(BaseDotNetNamespaceAsElement.FILTER, DotNetNamespaceAsElement.ChildrenFilter.ONLY_ELEMENTS);

	if(myNameWithAt.charAt(0) == '@')
	{
		return CSharpResolveUtil.mergeGroupsToIterable(context.findByName(myNameWithAt.substring(1, myNameWithAt.length()), deep, options));
	}
	else
	{
		Collection<PsiElement> array = ContainerUtil2.concat(context.findByName(myNameWithAt, deep, options), context.findByName(myNameWithAt + AttributeSuffix, deep, options));

		List<PsiElement> collection = CSharpResolveUtil.mergeGroupsToIterable(array);

		return ContainerUtil.findAll(collection, element -> element instanceof CSharpTypeDeclaration && DotNetInheritUtil.isAttribute((CSharpTypeDeclaration) element));
	}
}
 
Example 2
Source File: IdeKeyEventDispatcher.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static ListPopupStep buildStep(@Nonnull final List<Pair<AnAction, KeyStroke>> actions, final DataContext ctx) {
  return new BaseListPopupStep<Pair<AnAction, KeyStroke>>("Choose an action", ContainerUtil.findAll(actions, pair -> {
    final AnAction action = pair.getFirst();
    final Presentation presentation = action.getTemplatePresentation().clone();
    AnActionEvent event = new AnActionEvent(null, ctx, ActionPlaces.UNKNOWN, presentation, ActionManager.getInstance(), 0);

    ActionUtil.performDumbAwareUpdate(LaterInvocator.isInModalContext(), action, event, true);
    return presentation.isEnabled() && presentation.isVisible();
  })) {
    @Override
    public PopupStep onChosen(Pair<AnAction, KeyStroke> selectedValue, boolean finalChoice) {
      invokeAction(selectedValue.getFirst(), ctx);
      return FINAL_CHOICE;
    }
  };
}
 
Example 3
Source File: StubTreeLoaderImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void diagnoseLengthMismatch(VirtualFile vFile, boolean wasIndexedAlready, @Nullable Document document, boolean saved, @Nullable PsiFile cachedPsi) {
  String message = "Outdated stub in index: " +
                   vFile +
                   " " +
                   getIndexingStampInfo(vFile) +
                   ", doc=" +
                   document +
                   ", docSaved=" +
                   saved +
                   ", wasIndexedAlready=" +
                   wasIndexedAlready +
                   ", queried at " +
                   vFile.getTimeStamp();
  message += "\ndoc length=" + (document == null ? -1 : document.getTextLength()) + "\nfile length=" + vFile.getLength();
  if (cachedPsi != null) {
    message += "\ncached PSI " + cachedPsi.getClass();
    if (cachedPsi instanceof PsiFileImpl && ((PsiFileImpl)cachedPsi).isContentsLoaded()) {
      message += "\nPSI length=" + cachedPsi.getTextLength();
    }
    List<Project> projects = ContainerUtil.findAll(ProjectManager.getInstance().getOpenProjects(), p -> PsiManagerEx.getInstanceEx(p).getFileManager().findCachedViewProvider(vFile) != null);
    message += "\nprojects with file: " + (LOG.isDebugEnabled() ? projects.toString() : projects.size());
  }

  processError(vFile, message, new Exception());
}
 
Example 4
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 5
Source File: PathsVerifier.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public Collection<FilePatch> filterBadFileTypePatches() {
  List<Pair<VirtualFile, ApplyTextFilePatch>> failedTextPatches =
          ContainerUtil.findAll(myTextPatches, new Condition<Pair<VirtualFile, ApplyTextFilePatch>>() {
            @Override
            public boolean value(Pair<VirtualFile, ApplyTextFilePatch> textPatch) {
              final VirtualFile file = textPatch.getFirst();
              if (file.isDirectory()) return false;
              return !isFileTypeOk(file);
            }
          });
  myTextPatches.removeAll(failedTextPatches);
  return ContainerUtil.map(failedTextPatches, new Function<Pair<VirtualFile, ApplyTextFilePatch>, FilePatch>() {
    @Override
    public FilePatch fun(Pair<VirtualFile, ApplyTextFilePatch> patchInfo) {
      return patchInfo.getSecond().getPatch();
    }
  });
}
 
Example 6
Source File: SelectInManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
public SelectInTarget[] getTargets() {
  checkLoadExtensions();
  SelectInTarget[] targets = myTargets.toArray(new SelectInTarget[myTargets.size()]);
  Arrays.sort(targets, new SelectInTargetComparator());

  if (DumbService.getInstance(myProject).isDumb()) {
    final List<SelectInTarget> awareList = (List)ContainerUtil.findAll(targets, DumbAware.class);
    return awareList.toArray(new SelectInTarget[awareList.size()]);
  }

  return targets;
}
 
Example 7
Source File: CodeInsightTestFixtureImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public List<IntentionAction> filterAvailableIntentions(@Nonnull final String hint) {
  final List<IntentionAction> availableIntentions = getAvailableIntentions();
  return ContainerUtil.findAll(availableIntentions, new Condition<IntentionAction>() {
    @Override
    public boolean value(final IntentionAction intentionAction) {
      return intentionAction.getText().startsWith(hint);
    }
  });
}
 
Example 8
Source File: CompletionData.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected static PsiReference[] getReferences(final PsiMultiReference multiReference) {
  final PsiReference[] references = multiReference.getReferences();
  final List<PsiReference> hard = ContainerUtil.findAll(references, object -> !object.isSoft());
  if (!hard.isEmpty()) {
    return hard.toArray(new PsiReference[hard.size()]);
  }
  return references;
}
 
Example 9
Source File: ExternalLanguageAnnotators.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static List<ExternalAnnotator> allForFile(Language language, final PsiFile file) {
  List<ExternalAnnotator> annotators = INSTANCE.allForLanguage(language);
  final List<ExternalAnnotatorsFilter> filters = ExternalAnnotatorsFilter.EXTENSION_POINT_NAME.getExtensionList();
  return ContainerUtil.findAll(annotators, new Condition<ExternalAnnotator>() {
    @Override
    public boolean value(ExternalAnnotator annotator) {
      for (ExternalAnnotatorsFilter filter : filters) {
        if (filter.isProhibited(annotator, file)) {
          return false;
        }
      }
      return true;
    }
  });
}
 
Example 10
Source File: ChangeListUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static LocalChangeList tryToMatchWithExistingChangelist(@Nonnull ChangeListManager changeListManager,
                                                                @Nonnull final String defaultName) {
  List<LocalChangeList> matched = ContainerUtil.findAll(changeListManager.getChangeListsCopy(),
                                                        list -> defaultName.contains(list.getName().trim()));

  return matched.isEmpty() ? null : Collections.max(matched,
                                                    (o1, o2) -> Ints.compare(o1.getName().trim().length(), o2.getName().trim().length()));
}
 
Example 11
Source File: MoveChangesToAnotherListAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static List<LocalChangeList> getPreferredLists(@Nonnull List<LocalChangeList> lists, @Nonnull Collection<Change> changes) {
  final Set<Change> changesSet = ContainerUtil.newHashSet(changes);

  return ContainerUtil.findAll(lists, new Condition<LocalChangeList>() {
    @Override
    public boolean value(@Nonnull LocalChangeList list) {
      return !ContainerUtil.intersects(changesSet, list.getChanges());
    }
  });
}
 
Example 12
Source File: MultipleChangeListBrowser.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public List<VirtualFile> getIncludedUnversionedFiles() {
  return isShowUnversioned()
         ? ContainerUtil.findAll(myViewer.getIncludedChanges(), VirtualFile.class)
         : Collections.<VirtualFile>emptyList();
}
 
Example 13
Source File: KeymapUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isEventForAction(@Nonnull KeyEvent keyEvent, @Nonnull String actionId) {
  for (KeyboardShortcut shortcut : ContainerUtil.findAll(getActiveKeymapShortcuts(actionId).getShortcuts(), KeyboardShortcut.class)) {
    if (AWTKeyStroke.getAWTKeyStrokeForEvent(keyEvent) == shortcut.getFirstKeyStroke()) return true;
  }
  return false;
}
 
Example 14
Source File: FileReferenceHelperRegistrar.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static <T extends PsiFileSystemItem> List<FileReferenceHelper> getHelpers(@Nonnull final T psiFileSystemItem) {
  final VirtualFile file = psiFileSystemItem.getVirtualFile();
  if (file == null) return null;
  final Project project = psiFileSystemItem.getProject();
  return ContainerUtil.findAll(getHelpers(), fileReferenceHelper -> fileReferenceHelper.isMine(project, file));
}
 
Example 15
Source File: VcsLogFiltererImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
private VisiblePack getVisiblePack(@Nullable VisiblePack visiblePack, @Nonnull List<Request> requests) {
  ValidateRequest validateRequest = ContainerUtil.findLastInstance(requests, ValidateRequest.class);
  FilterRequest filterRequest = ContainerUtil.findLastInstance(requests, FilterRequest.class);
  SortTypeRequest sortTypeRequest = ContainerUtil.findLastInstance(requests, SortTypeRequest.class);
  List<MoreCommitsRequest> moreCommitsRequests = ContainerUtil.findAll(requests, MoreCommitsRequest.class);

  myRequestsToRun.addAll(moreCommitsRequests);
  if (filterRequest != null) {
    myFilters = filterRequest.filters;
  }
  if (sortTypeRequest != null) {
    mySortType = sortTypeRequest.sortType;
  }

  // On validate requests vs refresh requests.
  // Validate just changes validity (myIsValid field). If myIsValid is already what it needs to be it does nothing.
  // Refresh just tells that new data pack arrived. It does not make this filterer valid (or invalid).
  // So, this two requests bring here two completely different pieces of information.
  // Refresh requests are not explicitly used in this code. Basically what is done is a check that there are some requests apart from
  // instances of ValidateRequest (also we get into this method only when there are some requests in the queue).
  // Refresh request does not carry inside any additional information since current DataPack is just taken from VcsLogDataManager.

  if (!myIsValid) {
    if (validateRequest != null && validateRequest.validate) {
      myIsValid = true;
      return refresh(visiblePack, filterRequest, moreCommitsRequests);
    }
    else { // validateRequest == null || !validateRequest.validate
      // remember filters
      return visiblePack;
    }
  }
  else {
    if (validateRequest != null && !validateRequest.validate) {
      myIsValid = false;
      // invalidate
      VisiblePack frozenVisiblePack = visiblePack == null ? myVisiblePack : visiblePack;
      if (filterRequest != null) {
        frozenVisiblePack = refresh(visiblePack, filterRequest, moreCommitsRequests);
      }
      return new FakeVisiblePackBuilder(myLogData.getHashMap()).build(frozenVisiblePack);
    }

    Request nonValidateRequest = ContainerUtil.find(requests, request -> !(request instanceof ValidateRequest));

    if (nonValidateRequest != null) {
      // only doing something if there are some other requests
      return refresh(visiblePack, filterRequest, moreCommitsRequests);
    }
    else {
      return visiblePack;
    }
  }
}
 
Example 16
Source File: RecursionManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
void maybeMemoize(MyKey realKey, @Nullable Object result, Set<MyKey> preventionsBefore) {
  if (preventions.size() > preventionsBefore.size()) {
    List<MyKey> added = ContainerUtil.findAll(preventions, key -> key != realKey && !preventionsBefore.contains(key));
    intermediateCache.computeIfAbsent(realKey, __ -> new SmartList<>()).add(new SoftReference<>(new MemoizedValue(result, added.toArray(new MyKey[0]))));
  }
}
 
Example 17
Source File: VirtualFileManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public List<LocalFileProvider> getLocalFileProviders() {
  return ContainerUtil.findAll(myVirtualFileSystems.values(), LocalFileProvider.class);
}
 
Example 18
Source File: AbstractRepositoryManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
protected List<T> getRepositories(Class<T> type) {
  return ContainerUtil.findAll(myGlobalRepositoryManager.getRepositories(), type);
}
 
Example 19
Source File: PatchReader.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public List<TextFilePatch> getTextPatches() {
  return ContainerUtil.findAll(myPatches, TextFilePatch.class);
}
 
Example 20
Source File: ChangesBrowserBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Contract(pure = true)
@Nonnull
protected static <T> List<Change> findChanges(@Nonnull Collection<T> items) {
  return ContainerUtil.findAll(items, Change.class);
}