Java Code Examples for com.intellij.util.containers.ContainerUtil#map()
The following examples show how to use
com.intellij.util.containers.ContainerUtil#map() .
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: ResolvingTest.java From idea-gitignore with MIT License | 6 votes |
private void doTest(@NotNull String beforeText, String... expectedResolve) { myFixture.configureByText(GitFileType.INSTANCE, beforeText); PsiPolyVariantReference reference = ((PsiPolyVariantReference) myFixture.getReferenceAtCaretPosition()); assertNotNull(reference); final VirtualFile rootFile = myFixture.getFile().getContainingDirectory().getVirtualFile(); ResolveResult[] resolveResults = reference.multiResolve(true); List<String> actualResolve = ContainerUtil.map(resolveResults, new Function<ResolveResult, String>() { @Override public String fun(ResolveResult resolveResult) { PsiElement resolveResultElement = resolveResult.getElement(); assertNotNull(resolveResultElement); assertInstanceOf(resolveResultElement, PsiFileSystemItem.class); PsiFileSystemItem fileSystemItem = (PsiFileSystemItem) resolveResultElement; return VfsUtilCore.getRelativePath(fileSystemItem.getVirtualFile(), rootFile, '/'); } }); assertContainsElements(actualResolve, expectedResolve); }
Example 2
Source File: PackagesNotificationPanel.java From vue-for-idea with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void showErrors(@NotNull java.util.List<ValidationInfo> errors) { java.util.List<String> errorHtmlDescriptions = ContainerUtil.map(errors, new Function<ValidationInfo, String>() { public String fun(ValidationInfo info) { return info.getErrorHtmlDescription(); } }); String styleTag = UIUtil.getCssFontDeclaration(UIUtil.getLabelFont()); String html = "<html>" + styleTag + "<body><div style='padding-left:4px;'>" + StringUtil.join(errorHtmlDescriptions, "<div style='padding-top:2px;'/>") + "</div></body></html>"; for (ValidationInfo error : errors) { String linkText = error.getLinkText(); final JTextComponent component = error.getTextComponent(); if (linkText != null && component != null) { this.addLinkHandler(linkText, new Runnable() { public void run() { component.requestFocus(); } }); } } this.showError(html, null, null); }
Example 3
Source File: TimedCommitParser.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static List<TimedVcsCommit> log(@Nonnull List<String> commits) { return ContainerUtil.map(commits, new Function<String, TimedVcsCommit>() { @Override public TimedVcsCommit fun(String commit) { return parseTimestampParentHashes(commit); } }); }
Example 4
Source File: VcsDirtyScopeManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static Collection<FilePath> toFilePaths(@javax.annotation.Nullable Collection<VirtualFile> files) { if (files == null) return Collections.emptyList(); return ContainerUtil.map(files, new Function<VirtualFile, FilePath>() { @Override public FilePath fun(VirtualFile virtualFile) { return VcsUtil.getFilePath(virtualFile); } }); }
Example 5
Source File: SimpleElementGroupCollector.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Nullable @Override @RequiredReadAction protected CSharpElementGroup<E> compute() { Collection<E> elements = calcElements(); final DotNetGenericExtractor extractor = getExtractor(); if(extractor != DotNetGenericExtractor.EMPTY) { elements = ContainerUtil.map(elements, element -> element instanceof DotNetNamedElement ? (E) GenericUnwrapTool.extract((DotNetNamedElement) element, extractor) : element); } return elements.isEmpty() ? null : new CSharpElementGroupImpl<>(getProject(), myKey, elements); }
Example 6
Source File: DumpLookupElementWeights.java From consulo with Apache License 2.0 | 5 votes |
public static List<String> getLookupElementWeights(LookupImpl lookup, boolean hideSingleValued) { final Map<LookupElement, List<Pair<String, Object>>> weights = lookup.getRelevanceObjects(lookup.getItems(), hideSingleValued); return ContainerUtil.map(weights.entrySet(), new Function<Map.Entry<LookupElement, List<Pair<String, Object>>>, String>() { @Override public String fun(Map.Entry<LookupElement, List<Pair<String, Object>>> entry) { return entry.getKey().getLookupString() + "\t" + StringUtil.join(entry.getValue(), new Function<Pair<String, Object>, String>() { @Override public String fun(Pair<String, Object> pair) { return pair.first + "=" + pair.second; } }, ", "); } }); }
Example 7
Source File: JscsFinder.java From jscs-plugin with MIT License | 5 votes |
public static List<String> tryFindRulesAsString(final File projectRoot) { List<File> files = tryFindRules(projectRoot); return ContainerUtil.map(files, new Function<File, String>() { public String fun(File file) { // return FileUtils.makeRelative(projectRoot, file); return FileUtil.isAncestor(projectRoot, file, true) ? FileUtils.makeRelative(projectRoot, file) : file.toString(); } }); }
Example 8
Source File: VcsLogRefresherImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private List<GraphCommit<Integer>> compactCommits(@Nonnull List<? extends TimedVcsCommit> commits, @Nonnull final VirtualFile root) { StopWatch sw = StopWatch.start("compacting commits"); List<GraphCommit<Integer>> map = ContainerUtil.map(commits, new Function<TimedVcsCommit, GraphCommit<Integer>>() { @Nonnull @Override public GraphCommit<Integer> fun(@Nonnull TimedVcsCommit commit) { return compactCommit(commit, root); } }); myHashMap.flush(); sw.report(); return map; }
Example 9
Source File: GotoFileItemProvider.java From consulo with Apache License 2.0 | 5 votes |
private Iterable<FoundItemDescriptor<PsiFileSystemItem>> getItemsForNames(@Nonnull ProgressIndicator indicator, FindSymbolParameters parameters, List<MatchResult> matchResults) { List<PsiFileSystemItem> group = new ArrayList<>(); Map<PsiFileSystemItem, Integer> nesting = new HashMap<>(); Map<PsiFileSystemItem, Integer> matchDegrees = new HashMap<>(); for (MatchResult matchResult : matchResults) { ProgressManager.checkCanceled(); for (Object o : myModel.getElementsByName(matchResult.elementName, parameters, indicator)) { ProgressManager.checkCanceled(); if (o instanceof PsiFileSystemItem) { PsiFileSystemItem psiItem = (PsiFileSystemItem)o; String qualifier = getParentPath(psiItem); if (qualifier != null) { group.add(psiItem); nesting.put(psiItem, StringUtil.countChars(qualifier, '/')); matchDegrees.put(psiItem, matchResult.matchingDegree); } } } } if (group.size() > 1) { Collections.sort(group, Comparator.<PsiFileSystemItem, Integer>comparing(nesting::get). thenComparing(getPathProximityComparator()). thenComparing(myModel::getFullName)); } return ContainerUtil.map(group, item -> new FoundItemDescriptor<>(item, matchDegrees.get(item))); }
Example 10
Source File: FindUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public static UsageView showInUsageView(@Nullable PsiElement sourceElement, @Nonnull PsiElement[] targets, @Nonnull String title, @Nonnull final Project project) { if (targets.length == 0) return null; final UsageViewPresentation presentation = new UsageViewPresentation(); presentation.setCodeUsagesString(title); presentation.setTabName(title); presentation.setTabText(title); UsageTarget[] usageTargets = sourceElement == null ? UsageTarget.EMPTY_ARRAY : new UsageTarget[]{new PsiElement2UsageTargetAdapter(sourceElement)}; PsiElement[] primary = sourceElement == null ? PsiElement.EMPTY_ARRAY : new PsiElement[]{sourceElement}; UsageView view = UsageViewManager.getInstance(project).showUsages(usageTargets, Usage.EMPTY_ARRAY, presentation); SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(project); List<SmartPsiElementPointer> pointers = ContainerUtil.map(targets, smartPointerManager::createSmartPsiElementPointer); // usage view will load document/AST so still referencing all these PSI elements might lead to out of memory //noinspection UnusedAssignment targets = PsiElement.EMPTY_ARRAY; ProgressManager.getInstance().run(new Task.Backgroundable(project, "Updating Usage View ...") { @Override public void run(@Nonnull ProgressIndicator indicator) { for (final SmartPsiElementPointer pointer : pointers) { if (((UsageViewImpl)view).isDisposed()) break; ApplicationManager.getApplication().runReadAction(() -> { final PsiElement target = pointer.getElement(); if (target != null) { view.appendUsage(UsageInfoToUsageConverter.convert(primary, new UsageInfo(target))); } }); } UIUtil.invokeLaterIfNeeded(((UsageViewImpl)view)::expandAll); } }); return view; }
Example 11
Source File: UserFilterPopupComponent.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static List<String> collectUsers(@Nonnull VcsLogData logData) { List<String> users = ContainerUtil.map(logData.getAllUsers(), user -> { String shortPresentation = VcsUserUtil.getShortPresentation(user); Couple<String> firstAndLastName = VcsUserUtil.getFirstAndLastName(shortPresentation); if (firstAndLastName == null) return shortPresentation; return VcsUserUtil.capitalizeName(firstAndLastName.first) + " " + VcsUserUtil.capitalizeName(firstAndLastName.second); }); TreeSet<String> sortedUniqueUsers = new TreeSet<>(users); return new ArrayList<>(sortedUniqueUsers); }
Example 12
Source File: PermanentCommitsInfoImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public List<CommitId> convertToCommitIdList(@Nonnull Collection<Integer> commitIndexes) { return ContainerUtil.map(commitIndexes, new Function<Integer, CommitId>() { @Override public CommitId fun(Integer integer) { return getCommitId(integer); } }); }
Example 13
Source File: VcsLogClassicFilterUi.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull private static VcsLogStructureFilter createStructureFilter(@Nonnull List<String> values) { return new VcsLogStructureFilterImpl(ContainerUtil.map(values, VcsUtil::getFilePath)); }
Example 14
Source File: ComparisonManagerImpl.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull public static List<MergeLineFragment> convertIntoMergeLineFragments(@Nonnull List<MergeRange> conflicts) { return ContainerUtil.map(conflicts, ch -> new MergeLineFragmentImpl(ch.start1, ch.end1, ch.start2, ch.end2, ch.start3, ch.end3)); }
Example 15
Source File: FileRecursiveIterator.java From consulo with Apache License 2.0 | 4 votes |
FileRecursiveIterator(@Nonnull Module module) { this(module.getProject(), ContainerUtil.<PsiDirectory, VirtualFile>map(collectModuleDirectories(module), psiDir -> psiDir.getVirtualFile())); }
Example 16
Source File: EditorScrollingPositionKeeper.java From consulo with Apache License 2.0 | 4 votes |
public ForDocument(@Nullable Document document) { myKeepers = document == null ? Collections.emptyList() : ContainerUtil.map(EditorFactory.getInstance().getEditors(document), EditorScrollingPositionKeeper::new); }
Example 17
Source File: FileRecursiveIterator.java From consulo with Apache License 2.0 | 4 votes |
FileRecursiveIterator(@Nonnull Project project) { this(project, ContainerUtil.<PsiDirectory, VirtualFile>map(collectProjectDirectories(project), psiDir -> psiDir.getVirtualFile())); }
Example 18
Source File: FileRecursiveIterator.java From consulo with Apache License 2.0 | 4 votes |
FileRecursiveIterator(@Nonnull Project project, @Nonnull List<? extends PsiFile> roots) { this(project, ContainerUtil.<PsiFile, VirtualFile>map(roots, psiDir -> psiDir.getVirtualFile())); }
Example 19
Source File: FormatTextRanges.java From consulo with Apache License 2.0 | 4 votes |
public List<TextRange> getTextRanges() { List<TextRange> ranges = ContainerUtil.map(myRanges, FormatTextRange::getTextRange); ranges.sort(Segment.BY_START_OFFSET_THEN_END_OFFSET); return ranges; }
Example 20
Source File: WindowsDefenderChecker.java From consulo with Apache License 2.0 | 3 votes |
/** * Runs a powershell command to list the paths that are excluded from realtime scanning by Windows Defender. These * <p> * paths can contain environment variable references, as well as wildcards ('?', which matches a single character, and * '*', which matches any sequence of characters (but cannot match multiple nested directories; i.e., "foo\*\bar" would * match foo\baz\bar but not foo\baz\quux\bar)). The behavior of wildcards with respect to case-sensitivity is undocumented. * Returns a list of patterns, one for each exclusion path, that emulate how Windows Defender would interpret that path. */ @Nullable private static List<Pattern> getExcludedPatterns() { final Collection<String> paths = getWindowsDefenderProperty("ExclusionPath"); if (paths == null) return null; return ContainerUtil.map(paths, path -> wildcardsToRegex(expandEnvVars(path))); }