Java Code Examples for com.intellij.util.containers.ContainerUtil#filter()
The following examples show how to use
com.intellij.util.containers.ContainerUtil#filter() .
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: PatchChangeBuilder.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public static CharSequence getPatchedContent(@Nonnull AppliedTextPatch patch, @Nonnull String localContent) { PatchChangeBuilder builder = new PatchChangeBuilder(); builder.exec(patch.getHunks()); DocumentImpl document = new DocumentImpl(localContent, true); List<Hunk> appliedHunks = ContainerUtil.filter(builder.getHunks(), (h) -> h.getStatus() == HunkStatus.EXACTLY_APPLIED); ContainerUtil.sort(appliedHunks, Comparator.comparingInt(h -> h.getAppliedToLines().start)); for (int i = appliedHunks.size() - 1; i >= 0; i--) { Hunk hunk = appliedHunks.get(i); LineRange appliedTo = hunk.getAppliedToLines(); List<String> inserted = hunk.getInsertedLines(); DiffUtil.applyModification(document, appliedTo.start, appliedTo.end, inserted); } return document.getText(); }
Example 2
Source File: SchedulingWrapper.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull List<Runnable> cancelAndRemoveTasksFromQueue() { List<MyScheduledFutureTask> result = ContainerUtil.filter(delayQueue, new Condition<MyScheduledFutureTask>() { @Override public boolean value(MyScheduledFutureTask task) { if (task.getBackendExecutorService() == backendExecutorService) { task.cancel(false); return true; } return false; } }); delayQueue.removeAll(new HashSet<MyScheduledFutureTask>(result)); if (LOG.isTraceEnabled()) { LOG.trace("Shutdown. Drained tasks: " + result); } //noinspection unchecked return (List)result; }
Example 3
Source File: FileCopyPasteUtil.java From consulo with Apache License 2.0 | 6 votes |
@Nullable public static List<File> getFileList(@Nonnull final Transferable transferable) { try { if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { @SuppressWarnings({"unchecked"}) final List<File> fileList = (List<File>)transferable.getTransferData(DataFlavor.javaFileListFlavor); return ContainerUtil.filter(fileList, new Condition<File>() { @Override public boolean value(File file) { return !StringUtil.isEmptyOrSpaces(file.getPath()); } }); } else { return LinuxDragAndDropSupport.getFiles(transferable); } } catch (Exception ignore) { } return null; }
Example 4
Source File: AbstractServiceReference.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@NotNull @Override public Object[] getVariants() { ContainerCollectionResolver.ServiceCollector collector = ContainerCollectionResolver .ServiceCollector.create(getElement().getProject()); Collection<ContainerService> values = collector.getServices().values(); if(!usePrivateServices) { values = ContainerUtil.filter(values, service -> !service.isPrivate()); } List<LookupElement> results = new ArrayList<>(ServiceCompletionProvider.getLookupElements(null, values).getLookupElements()); return results.toArray(); }
Example 5
Source File: HideIgnoredFilesTreeStructureProvider.java From idea-gitignore with MIT License | 6 votes |
/** * If {@link IgnoreSettings#hideIgnoredFiles} is set to <code>true</code>, checks if specific * nodes are ignored and filters them out. * * @param parent the parent node * @param children the list of child nodes according to the default project structure * @param settings the current project view settings * @return the modified collection of child nodes */ @NotNull @Override public Collection<AbstractTreeNode<?>> modify(@NotNull AbstractTreeNode<?> parent, @NotNull Collection<AbstractTreeNode<?>> children, @Nullable ViewSettings settings) { if (!ignoreSettings.isHideIgnoredFiles() || children.isEmpty()) { return children; } return ContainerUtil.filter(children, node -> { if (node instanceof BasePsiNode) { final VirtualFile file = ((BasePsiNode) node).getVirtualFile(); return file != null && (!changeListManager.isIgnoredFile(file) && !ignoreManager.isFileIgnored(file) || ignoreManager.isFileTracked(file)); } return true; }); }
Example 6
Source File: ListTableWithButtons.java From consulo with Apache License 2.0 | 6 votes |
protected void removeSelected() { List<T> selected = getSelection(); if (!selected.isEmpty()) { myTableView.stopEditing(); setModified(); int selectedIndex = myTableView.getSelectionModel().getLeadSelectionIndex(); myTableView.scrollRectToVisible(myTableView.getCellRect(selectedIndex, 0, true)); selected = ContainerUtil.filter(selected, t -> canDeleteElement(t)); myElements.removeAll(selected); myTableView.getSelectionModel().clearSelection(); myTableView.getTableViewModel().setItems(myElements); int prev = selectedIndex - 1; if (prev >= 0) { myTableView.getComponent().getSelectionModel().setSelectionInterval(prev, prev); } else if (selectedIndex < myElements.size()) { myTableView.getComponent().getSelectionModel().setSelectionInterval(selectedIndex, selectedIndex); } } }
Example 7
Source File: PatchReader.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> getAdditionalInfo(@Nullable Set<String> paths) { ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> result; PatchSyntaxException e = myAdditionalInfoParser.getSyntaxException(); if (e != null) { result = () -> { throw e; }; } else { Map<String, Map<String, CharSequence>> additionalInfo = ContainerUtil.filter(myAdditionalInfoParser.getResultMap(), path -> paths == null || paths .contains(path)); result = () -> additionalInfo; } return result; }
Example 8
Source File: DiffUtil.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public static <T extends DiffTool> List<T> filterSuppressedTools(@Nonnull List<T> tools) { if (tools.size() < 2) return tools; final List<Class<? extends DiffTool>> suppressedTools = new ArrayList<>(); for (T tool : tools) { try { if (tool instanceof SuppressiveDiffTool) suppressedTools.addAll(((SuppressiveDiffTool)tool).getSuppressedTools()); } catch (Throwable e) { LOG.error(e); } } if (suppressedTools.isEmpty()) return tools; List<T> filteredTools = ContainerUtil.filter(tools, tool -> !suppressedTools.contains(tool.getClass())); return filteredTools.isEmpty() ? tools : filteredTools; }
Example 9
Source File: VcsLogContentProvider.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static String generateShortName(@Nonnull ToolWindow toolWindow) { TabbedContent tabbedContent = ContentUtilEx.findTabbedContent(toolWindow.getContentManager(), TAB_NAME); if (tabbedContent != null) { return String.valueOf(tabbedContent.getTabs().size() + 1); } else { List<Content> contents = ContainerUtil.filter(toolWindow.getContentManager().getContents(), content -> TAB_NAME.equals(content.getUserData(Content.TAB_GROUP_NAME_KEY))); return String.valueOf(contents.size() + 1); } }
Example 10
Source File: OverrideUtil.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Nonnull @RequiredReadAction public static Collection<PsiElement> getAllMembers(@Nonnull final PsiElement targetTypeDeclaration, @Nonnull GlobalSearchScope scope, @Nonnull DotNetGenericExtractor extractor, boolean completion, boolean overrideTool) { final CommonProcessors.CollectProcessor<PsiElement> collectProcessor = new CommonProcessors.CollectProcessor<>(); CSharpResolveContext context = CSharpResolveContextUtil.createContext(extractor, scope, targetTypeDeclaration); // process method & properties context.processElements(collectProcessor, true); // process index methods CSharpElementGroup<CSharpIndexMethodDeclaration> group = context.indexMethodGroup(true); if(group != null) { group.process(collectProcessor); } Collection<PsiElement> results = collectProcessor.getResults(); List<PsiElement> mergedElements = CSharpResolveUtil.mergeGroupsToIterable(results); List<PsiElement> psiElements = OverrideUtil.filterOverrideElements(targetTypeDeclaration, mergedElements, OverrideProcessor.ALWAYS_TRUE); List<PsiElement> elements = CSharpResolveUtil.mergeGroupsToIterable(psiElements); if(overrideTool) { // filter self methods, we need it in circular extends elements = ContainerUtil.filter(elements, element -> { ProgressManager.checkCanceled(); return element.getParent() != targetTypeDeclaration; }); } return completion ? elements : ContainerUtil.filter(elements, element -> { ProgressManager.checkCanceled(); return !(element instanceof DotNetTypeDeclaration); }); }
Example 11
Source File: TypeHintSuggestionProvider.java From idea-php-toolbox with MIT License | 5 votes |
@Nullable @Override public SuggestedNameInfo getSuggestedNames(PsiElement psiElement, PsiElement psiElement1, Set<String> set) { if(!(psiElement instanceof Parameter)) { return null; } List<String> filter = ContainerUtil.filter(PhpNameSuggestionUtil.variableNameByType((Parameter) psiElement, psiElement.getProject(), false), s -> !StringUtil.containsChar(s, '\\')); if(filter.size() == 0) { return null; } for (String item : filter) { for(String end: TRIM_STRINGS) { // ending if(item.toLowerCase().endsWith(end)) { item = item.substring(0, item.length() - end.length()); } // remove starting if(item.toLowerCase().startsWith(end)) { item = WordUtils.uncapitalize(item.substring(end.length())); } } if(StringUtils.isNotBlank(item)) { set.add(item); } } return null; }
Example 12
Source File: RunManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
private void doSaveOrder(@Nullable Comparator<RunnerAndConfigurationSettings> comparator) { List<RunnerAndConfigurationSettings> sorted = new ArrayList<>(ContainerUtil.filter(myConfigurations.values(), o -> !(o.getType() instanceof UnknownConfigurationType))); if (comparator != null) sorted.sort(comparator); myOrder.clear(); for (RunnerAndConfigurationSettings each : sorted) { myOrder.add(each.getUniqueID()); } }
Example 13
Source File: EnableMatchCaseAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void update(@Nonnull AnActionEvent e) { super.update(e); VcsLogUi ui = e.getData(VcsLogDataKeys.VCS_LOG_UI); VcsLogUiProperties properties = e.getData(VcsLogInternalDataKeys.LOG_UI_PROPERTIES); if (ui != null && properties != null && properties.exists(MainVcsLogUiProperties.TEXT_FILTER_MATCH_CASE)) { boolean regexEnabled = properties.exists(MainVcsLogUiProperties.TEXT_FILTER_REGEX) && properties.get(MainVcsLogUiProperties.TEXT_FILTER_REGEX); if (!regexEnabled) { e.getPresentation().setText(MATCH_CASE); } else { Collection<VcsLogProvider> providers = ContainerUtil.newLinkedHashSet(ui.getDataPack().getLogProviders().values()); List<VcsLogProvider> supported = ContainerUtil.filter(providers, p -> VcsLogProperties.get(p, VcsLogProperties.CASE_INSENSITIVE_REGEX)); e.getPresentation().setVisible(true); e.getPresentation().setEnabled(!supported.isEmpty()); if (providers.size() == supported.size() || supported.isEmpty()) { e.getPresentation().setText(MATCH_CASE); } else { String supportedText = StringUtil.join(ContainerUtil.map(supported, p -> p.getSupportedVcs().getName().toLowerCase()), ", "); e.getPresentation().setText(MATCH_CASE + " (" + supportedText + " only)"); } } } }
Example 14
Source File: VcsDirectoryConfigurationPanel.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private List<MapInfo> getSelectedRegisteredRoots() { Collection<MapInfo> selection = myDirectoryMappingTable.getSelection(); return ContainerUtil.filter(selection, new Condition<MapInfo>() { @Override public boolean value(MapInfo info) { return info.type == MapInfo.Type.NORMAL || info.type == MapInfo.Type.INVALID; } }); }
Example 15
Source File: BreakpointsDialog.java From consulo with Apache License 2.0 | 5 votes |
private void saveBreakpointsDialogState() { final XBreakpointsDialogState dialogState = new XBreakpointsDialogState(); final List<XBreakpointGroupingRule> rulesEnabled = ContainerUtil.filter(myRulesEnabled, rule -> !rule.isAlwaysEnabled()); dialogState.setSelectedGroupingRules(new HashSet<String>(ContainerUtil.map(rulesEnabled, rule -> rule.getId()))); getBreakpointManager().setBreakpointsDialogSettings(dialogState); }
Example 16
Source File: ZipEntryMap.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull @Override public Collection<ArchiveHandler.EntryInfo> values() { return ContainerUtil.filter(entries, Condition.NOT_NULL); }
Example 17
Source File: SearchEverywhereUI.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull private List<SearchEverywhereContributor<?>> getAllTabContributors() { return ContainerUtil.filter(myShownContributors, contributor -> myContributorsFilter.isSelected(contributor.getSearchProviderId())); }
Example 18
Source File: ChooseByNameBase.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull protected List<Object> getChosenElements() { return ContainerUtil.filter(myList.getSelectedValuesList(), o -> o != null && !isSpecialElement(o)); }
Example 19
Source File: RunManagerImpl.java From consulo with Apache License 2.0 | 4 votes |
@Override @Nonnull public List<RunnerAndConfigurationSettings> getTempConfigurationsList() { List<RunnerAndConfigurationSettings> configurations = ContainerUtil.filter(myConfigurations.values(), RunnerAndConfigurationSettings::isTemporary); return Collections.unmodifiableList(configurations); }
Example 20
Source File: TrafficLightRenderer.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull protected DaemonCodeAnalyzerStatus getDaemonCodeAnalyzerStatus(@Nonnull SeverityRegistrar severityRegistrar) { DaemonCodeAnalyzerStatus status = new DaemonCodeAnalyzerStatus(); PsiFile psiFile = getPsiFile(); if (psiFile == null) { status.reasonWhyDisabled = DaemonBundle.message("process.title.no.file"); status.errorAnalyzingFinished = true; return status; } if (myProject.isDisposed()) { status.reasonWhyDisabled = DaemonBundle.message("process.title.project.is.disposed"); status.errorAnalyzingFinished = true; return status; } if (!myDaemonCodeAnalyzer.isHighlightingAvailable(psiFile)) { if (!psiFile.isPhysical()) { status.reasonWhyDisabled = DaemonBundle.message("process.title.file.is.generated"); status.errorAnalyzingFinished = true; return status; } if (psiFile instanceof PsiCompiledElement) { status.reasonWhyDisabled = DaemonBundle.message("process.title.file.is.decompiled"); status.errorAnalyzingFinished = true; return status; } final FileType fileType = psiFile.getFileType(); if (fileType.isBinary()) { status.reasonWhyDisabled = DaemonBundle.message("process.title.file.is.binary"); status.errorAnalyzingFinished = true; return status; } status.reasonWhyDisabled = DaemonBundle.message("process.title.highlighting.is.disabled.for.this.file"); status.errorAnalyzingFinished = true; return status; } FileViewProvider provider = psiFile.getViewProvider(); Set<Language> languages = provider.getLanguages(); HighlightingSettingsPerFile levelSettings = HighlightingSettingsPerFile.getInstance(myProject); boolean shouldHighlight = languages.isEmpty(); for (Language language : languages) { PsiFile root = provider.getPsi(language); FileHighlightingSetting level = levelSettings.getHighlightingSettingForRoot(root); shouldHighlight |= level != FileHighlightingSetting.SKIP_HIGHLIGHTING; } if (!shouldHighlight) { status.reasonWhyDisabled = DaemonBundle.message("process.title.highlighting.level.is.none"); status.errorAnalyzingFinished = true; return status; } if (HeavyProcessLatch.INSTANCE.isRunning()) { Map.Entry<String, HeavyProcessLatch.Type> processEntry = HeavyProcessLatch.INSTANCE.getRunningOperation(); if (processEntry != null) { status.reasonWhySuspended = processEntry.getKey(); status.heavyProcessType = processEntry.getValue(); } else { status.reasonWhySuspended = DaemonBundle.message("process.title.heavy.operation.is.running"); status.heavyProcessType = HeavyProcessLatch.Type.Processing; } status.errorAnalyzingFinished = true; return status; } status.errorCount = errorCount.clone(); List<ProgressableTextEditorHighlightingPass> passesToShowProgressFor = myDaemonCodeAnalyzer.getPassesToShowProgressFor(myDocument); status.passes = ContainerUtil.filter(passesToShowProgressFor, p -> !StringUtil.isEmpty(p.getPresentableName()) && p.getProgress() >= 0); status.errorAnalyzingFinished = myDaemonCodeAnalyzer.isAllAnalysisFinished(psiFile); status.reasonWhySuspended = myDaemonCodeAnalyzer.isUpdateByTimerEnabled() ? null : DaemonBundle.message("process.title.highlighting.is.paused.temporarily"); fillDaemonCodeAnalyzerErrorsStatus(status, severityRegistrar); return status; }