Java Code Examples for com.intellij.util.containers.ContainerUtil#process()
The following examples show how to use
com.intellij.util.containers.ContainerUtil#process() .
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: GlobalSearchScope.java From consulo with Apache License 2.0 | 6 votes |
@Override public int compare(@Nonnull final VirtualFile file1, @Nonnull final VirtualFile file2) { final int[] result = {0}; ContainerUtil.process(myScopes, new Processor<GlobalSearchScope>() { @Override public boolean process(GlobalSearchScope scope) { int res1 = scope.contains(file1) && scope.contains(file2) ? scope.compare(file1, file2) : 0; if (result[0] == 0) { result[0] = res1; return true; } if ((result[0] > 0) != (res1 > 0)) { result[0] = 0; return false; } return true; } }); return result[0]; }
Example 2
Source File: CSharpMethodImplementationsSearcher.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override public boolean execute(@Nonnull DefinitionsScopedSearch.SearchParameters queryParameters, @Nonnull Processor<? super PsiElement> consumer) { PsiElement element = queryParameters.getElement(); if(element instanceof DotNetVirtualImplementOwner) { Collection<DotNetVirtualImplementOwner> members = ReadAction.compute(() -> OverrideUtil.collectOverridenMembers((DotNetVirtualImplementOwner) element)); return ContainerUtil.process(members, consumer); } return true; }
Example 3
Source File: GotoActionItemProvider.java From consulo with Apache License 2.0 | 5 votes |
private static boolean processItems(String pattern, JBIterable<?> items, Processor<? super MatchedValue> consumer) { List<MatchedValue> matched = ContainerUtil.newArrayList(items.map(o -> o instanceof MatchedValue ? (MatchedValue)o : new MatchedValue(o, pattern))); try { Collections.sort(matched, (o1, o2) -> o1.compareWeights(o2)); } catch (IllegalArgumentException e) { LOG.error("Comparison method violates its general contract with pattern '" + pattern + "'", e); } return ContainerUtil.process(matched, consumer); }
Example 4
Source File: GotoFileItemProvider.java From consulo with Apache License 2.0 | 5 votes |
boolean processFiles(@Nonnull FindSymbolParameters parameters, @Nonnull Processor<FoundItemDescriptor<?>> processor, @Nonnull Ref<Boolean> hasSuggestions, @Nonnull DirectoryPathMatcher dirMatcher) { MinusculeMatcher qualifierMatcher = getQualifiedNameMatcher(parameters.getLocalPatternName()); List<MatchResult> matchingNames = this.matchingNames; if (patternSuffix.length() <= 3 && !dirMatcher.dirPattern.isEmpty()) { // just enumerate over files // otherwise there are too many names matching the remaining few letters, and querying index for all of them with a very constrained scope is expensive Set<String> existingNames = dirMatcher.findFileNamesMatchingIfCheap(patternSuffix.charAt(0), matcher); if (existingNames != null) { matchingNames = ContainerUtil.filter(matchingNames, mr -> existingNames.contains(mr.elementName)); } } List<List<MatchResult>> groups = groupByMatchingDegree(!parameters.getCompletePattern().startsWith("*"), matchingNames); for (List<MatchResult> group : groups) { JBIterable<FoundItemDescriptor<PsiFileSystemItem>> filesMatchingPath = getFilesMatchingPath(parameters, group, dirMatcher, indicator); Iterable<FoundItemDescriptor<PsiFileSystemItem>> matchedFiles = parameters.getLocalPatternName().isEmpty() ? filesMatchingPath : matchQualifiers(qualifierMatcher, filesMatchingPath.map(res -> res.getItem())); matchedFiles = moveDirectoriesToEnd(matchedFiles); Processor<FoundItemDescriptor<PsiFileSystemItem>> trackingProcessor = res -> { hasSuggestions.set(true); return processor.process(res); }; if (!ContainerUtil.process(matchedFiles, trackingProcessor)) { return false; } } // let the framework switch to searching outside project to display these well-matching suggestions // instead of worse-matching ones in project (that are very expensive to calculate) return hasSuggestions.get() || parameters.isSearchInLibraries() || !hasSuggestionsOutsideProject(parameters.getCompletePattern(), groups, dirMatcher); }
Example 5
Source File: ShelveChangesManager.java From consulo with Apache License 2.0 | 5 votes |
private void filterNonValidShelvedChangeLists() { final List<ShelvedChangeList> allSchemes = ContainerUtil.newArrayList(mySchemeManager.getAllSchemes()); ContainerUtil.process(allSchemes, new Processor<ShelvedChangeList>() { @Override public boolean process(ShelvedChangeList shelvedChangeList) { if (!shelvedChangeList.isValid()) { mySchemeManager.removeScheme(shelvedChangeList); } return true; } }); }
Example 6
Source File: AbstractRepositoryManager.java From consulo with Apache License 2.0 | 5 votes |
@Override public void updateAllRepositories() { ContainerUtil.process(getRepositories(), repo -> { repo.update(); return true; }); }
Example 7
Source File: FileTrees.java From consulo with Apache License 2.0 | 5 votes |
private void forEachCachedPsi(Consumer<? super StubBasedPsiElementBase> consumer) { ContainerUtil.process(myRefToPsi, ref -> { StubBasedPsiElementBase psi = SoftReference.dereference(ref); if (psi != null) { consumer.accept(psi); } return true; }); }
Example 8
Source File: DocumentImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean processRangeMarkersOverlappingWith(int start, int end, @Nonnull Processor<? super RangeMarker> processor) { TextRangeInterval interval = new TextRangeInterval(start, end); MarkupIterator<RangeMarkerEx> iterator = IntervalTreeImpl.mergingOverlappingIterator(myRangeMarkers, interval, myPersistentRangeMarkers, interval, RangeMarker.BY_START_OFFSET); try { return ContainerUtil.process(iterator, processor); } finally { iterator.dispose(); } }
Example 9
Source File: IdeKeyEventDispatcher.java From consulo with Apache License 2.0 | 5 votes |
private void registerActions(@Nonnull final KeyStroke firstKeyStroke, @Nonnull final List<Pair<AnAction, KeyStroke>> actions, final DataContext ctx) { ContainerUtil.process(actions, pair -> { final String actionText = pair.getFirst().getTemplatePresentation().getText(); final AbstractAction a = new AbstractAction() { @Override public void actionPerformed(final ActionEvent e) { cancel(); invokeAction(pair.getFirst(), ctx); } }; final KeyStroke keyStroke = pair.getSecond(); if (keyStroke != null) { registerAction(actionText, keyStroke, a); if (keyStroke.getModifiers() == 0) { // do a little trick here, so if I will press Command+R and the second keystroke is just 'R', // I want to be able to hold the Command while pressing 'R' final KeyStroke additionalKeyStroke = KeyStroke.getKeyStroke(keyStroke.getKeyCode(), firstKeyStroke.getModifiers()); final String _existing = getActionForKeyStroke(additionalKeyStroke); if (_existing == null) registerAction("__additional__" + actionText, additionalKeyStroke, a); } } return true; }); }
Example 10
Source File: FileDropHandler.java From consulo with Apache License 2.0 | 5 votes |
@Override public void handleDrop(@Nonnull final Transferable t, @Nullable final Project project, EditorWindow editorWindow) { if (project != null) { final List<File> fileList = FileCopyPasteUtil.getFileList(t); if (fileList != null) { boolean dropResult = ContainerUtil.process(Extensions.getExtensions(CustomFileDropHandler.CUSTOM_DROP_HANDLER_EP, project), handler -> !(handler.canHandle(t, myEditor) && handler.handleDrop(t, myEditor, project))); if (!dropResult) return; openFiles(project, fileList, editorWindow); } } }
Example 11
Source File: SpeedSearchUtil.java From consulo with Apache License 2.0 | 5 votes |
public static void appendColoredFragments(final SimpleColoredComponent simpleColoredComponent, final String text, Iterable<TextRange> colored, final SimpleTextAttributes plain, final SimpleTextAttributes highlighted) { final List<Pair<String, Integer>> searchTerms = new ArrayList<Pair<String, Integer>>(); for (TextRange fragment : colored) { searchTerms.add(Pair.create(fragment.substring(text), fragment.getStartOffset())); } final int[] lastOffset = {0}; ContainerUtil.process(searchTerms, new Processor<Pair<String, Integer>>() { @Override public boolean process(Pair<String, Integer> pair) { if (pair.second > lastOffset[0]) { simpleColoredComponent.append(text.substring(lastOffset[0], pair.second), plain); } simpleColoredComponent.append(text.substring(pair.second, pair.second + pair.first.length()), highlighted); lastOffset[0] = pair.second + pair.first.length(); return true; } }); if (lastOffset[0] < text.length()) { simpleColoredComponent.append(text.substring(lastOffset[0]), plain); } }
Example 12
Source File: CSharpBaseResolveContext.java From consulo-csharp with Apache License 2.0 | 5 votes |
@RequiredReadAction public boolean processElementsImpl(@Nonnull Processor<PsiElement> processor) { Map<String, CSharpElementGroup<PsiElement>> map = myOtherCollectorValue.getValue().toMap(); return map == null || ContainerUtil.process(map.values(), processor); }
Example 13
Source File: DesktopEditorErrorPanelUI.java From consulo with Apache License 2.0 | 4 votes |
private void drawMarkup(@Nonnull final Graphics g, int startOffset, int endOffset, @Nonnull MarkupModelEx markup1, @Nonnull MarkupModelEx markup2) { final Queue<PositionedStripe> thinEnds = new PriorityQueue<>(5, (o1, o2) -> o1.yEnd - o2.yEnd); final Queue<PositionedStripe> wideEnds = new PriorityQueue<>(5, (o1, o2) -> o1.yEnd - o2.yEnd); // sorted by layer final List<PositionedStripe> thinStripes = new ArrayList<>(); // layer desc final List<PositionedStripe> wideStripes = new ArrayList<>(); // layer desc final int[] thinYStart = new int[1]; // in range 0..yStart all spots are drawn final int[] wideYStart = new int[1]; // in range 0..yStart all spots are drawn MarkupIterator<RangeHighlighterEx> iterator1 = markup1.overlappingIterator(startOffset, endOffset); MarkupIterator<RangeHighlighterEx> iterator2 = markup2.overlappingIterator(startOffset, endOffset); MarkupIterator<RangeHighlighterEx> iterator = MarkupIterator.mergeIterators(iterator1, iterator2, RangeHighlighterEx.BY_AFFECTED_START_OFFSET); try { ContainerUtil.process(iterator, highlighter -> { Color color = highlighter.getErrorStripeMarkColor(); if (color == null) return true; boolean isThin = highlighter.isThinErrorStripeMark(); int[] yStart = isThin ? thinYStart : wideYStart; List<PositionedStripe> stripes = isThin ? thinStripes : wideStripes; Queue<PositionedStripe> ends = isThin ? thinEnds : wideEnds; ProperTextRange range = myPanel.offsetsToYPositions(highlighter.getStartOffset(), highlighter.getEndOffset()); final int ys = range.getStartOffset(); int ye = range.getEndOffset(); if (ye - ys < myPanel.getMarkupModel().getMinMarkHeight()) ye = ys + myPanel.getMarkupModel().getMinMarkHeight(); yStart[0] = drawStripesEndingBefore(ys, ends, stripes, g, yStart[0]); final int layer = highlighter.getLayer(); PositionedStripe stripe = null; int i; for (i = 0; i < stripes.size(); i++) { PositionedStripe s = stripes.get(i); if (s.layer == layer) { stripe = s; break; } if (s.layer < layer) { break; } } if (stripe == null) { // started new stripe, draw previous above if (i == 0 && yStart[0] != ys) { if (!stripes.isEmpty()) { PositionedStripe top = stripes.get(0); drawSpot(g, top.thin, yStart[0], ys, top.color); } yStart[0] = ys; } stripe = new PositionedStripe(color, ye, isThin, layer); stripes.add(i, stripe); ends.offer(stripe); } else { if (stripe.yEnd < ye) { if (!color.equals(stripe.color)) { // paint previous stripe on this layer if (i == 0 && yStart[0] != ys) { drawSpot(g, stripe.thin, yStart[0], ys, stripe.color); yStart[0] = ys; } stripe.color = color; } // key changed, reinsert into queue ends.remove(stripe); stripe.yEnd = ye; ends.offer(stripe); } } return true; }); } finally { iterator.dispose(); } drawStripesEndingBefore(Integer.MAX_VALUE, thinEnds, thinStripes, g, thinYStart[0]); drawStripesEndingBefore(Integer.MAX_VALUE, wideEnds, wideStripes, g, wideYStart[0]); }
Example 14
Source File: CollectionQuery.java From consulo with Apache License 2.0 | 4 votes |
@Override public boolean forEach(@Nonnull final Processor<? super T> consumer) { return ContainerUtil.process(myCollection, consumer); }
Example 15
Source File: ArrayQuery.java From consulo with Apache License 2.0 | 4 votes |
@Override public boolean forEach(@Nonnull final Processor<? super T> consumer) { return ContainerUtil.process(myArray, consumer); }
Example 16
Source File: ModuleRootsProcessor.java From consulo with Apache License 2.0 | 4 votes |
public void processFileUrls(@Nonnull ModuleRootModel moduleRootModel, @Nonnull Predicate<ContentFolderTypeProvider> predicate, @Nonnull Processor<String> processor) { String[] files = getUrls(moduleRootModel, predicate); ContainerUtil.process(files, processor); }
Example 17
Source File: ModuleRootsProcessor.java From consulo with Apache License 2.0 | 4 votes |
public void processFiles(@Nonnull ModuleRootModel moduleRootModel, @Nonnull Predicate<ContentFolderTypeProvider> predicate, @Nonnull Processor<VirtualFile> processor) { VirtualFile[] files = getFiles(moduleRootModel, predicate); ContainerUtil.process(files, processor); }