Java Code Examples for com.intellij.util.containers.MultiMap#keySet()
The following examples show how to use
com.intellij.util.containers.MultiMap#keySet() .
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: PsiSearchHelperImpl.java From consulo with Apache License 2.0 | 6 votes |
private boolean processCandidates(@Nonnull final Map<RequestWithProcessor, Processor<PsiElement>> localProcessors, @Nonnull final MultiMap<VirtualFile, RequestWithProcessor> candidateFiles, @Nonnull ProgressIndicator progress, int totalSize, int alreadyProcessedFiles) { List<VirtualFile> files = new ArrayList<>(candidateFiles.keySet()); return processPsiFileRoots(files, totalSize, alreadyProcessedFiles, progress, psiRoot -> { final VirtualFile vfile = psiRoot.getVirtualFile(); for (final RequestWithProcessor singleRequest : candidateFiles.get(vfile)) { Processor<PsiElement> localProcessor = localProcessors.get(singleRequest); if (!localProcessor.process(psiRoot)) { return false; } } return true; }); }
Example 2
Source File: SimpleRefGroup.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public static List<Color> getColors(@Nonnull Collection<VcsRef> refs) { MultiMap<VcsRefType, VcsRef> referencesByType = ContainerUtil.groupBy(refs, VcsRef::getType); if (referencesByType.size() == 1) { Map.Entry<VcsRefType, Collection<VcsRef>> firstItem = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(referencesByType.entrySet())); boolean multiple = firstItem.getValue().size() > 1; Color color = firstItem.getKey().getBackgroundColor(); return multiple ? Arrays.asList(color, color) : Collections.singletonList(color); } else { List<Color> colorsList = ContainerUtil.newArrayList(); for (VcsRefType type : referencesByType.keySet()) { if (referencesByType.get(type).size() > 1) { colorsList.add(type.getBackgroundColor()); } colorsList.add(type.getBackgroundColor()); } return colorsList; } }
Example 3
Source File: VcsLogRepoSizeCollector.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull @Override public Set<UsageDescriptor> getProjectUsages(@Nonnull Project project) throws CollectUsagesException { VcsProjectLog projectLog = VcsProjectLog.getInstance(project); VcsLogData logData = projectLog.getDataManager(); if (logData != null) { DataPack dataPack = logData.getDataPack(); if (dataPack.isFull()) { PermanentGraph<Integer> permanentGraph = dataPack.getPermanentGraph(); MultiMap<VcsKey, VirtualFile> groupedRoots = groupRootsByVcs(dataPack.getLogProviders()); Set<UsageDescriptor> usages = ContainerUtil.newHashSet(); usages.add(StatisticsUtilKt.getCountingUsage("data.commit.count", permanentGraph.getAllCommits().size(), asList(0, 1, 100, 1000, 10 * 1000, 100 * 1000, 500 * 1000))); for (VcsKey vcs : groupedRoots.keySet()) { usages.add(StatisticsUtilKt.getCountingUsage("data." + vcs.getName().toLowerCase() + ".root.count", groupedRoots.get(vcs).size(), asList(0, 1, 2, 5, 8, 15, 30, 50, 100, 500, 1000))); } return usages; } } return Collections.emptySet(); }
Example 4
Source File: VcsLogUserFilterTest.java From consulo with Apache License 2.0 | 6 votes |
public void testWeirdCharacters() throws Exception { List<String> names = ContainerUtil.newArrayList(); for (Character c : UserNameRegex.EXTENDED_REGEX_CHARS) { String name = "user" + Character.toString(c) + "userovich" + c.hashCode(); // hashCode is required so that uses wont be synonyms names.add(name); names.add(name + "@company.com"); } MultiMap<VcsUser, String> commits = generateHistory(ArrayUtil.toStringArray(names)); List<VcsCommitMetadata> metadata = generateMetadata(commits); StringBuilder builder = new StringBuilder(); for (VcsUser user : commits.keySet()) { checkFilterForUser(user, commits.keySet(), commits.get(user), metadata, builder); } assertFilteredCorrectly(builder); }
Example 5
Source File: StatisticsWeigher.java From consulo with Apache License 2.0 | 6 votes |
private TreeMap<Integer, List<LookupElement>> buildMapByWeight(Iterable<LookupElement> source) { MultiMap<String, LookupElement> byName = MultiMap.create(); List<LookupElement> noStats = new ArrayList<>(); for (LookupElement element : source) { String string = element.getLookupString(); if (myStringsWithWeights.contains(string)) { byName.putValue(string, element); } else { noStats.add(element); } } TreeMap<Integer, List<LookupElement>> map = new TreeMap<>(); map.put(0, noStats); for (String s : byName.keySet()) { List<LookupElement> group = (List<LookupElement>)byName.get(s); Collections.sort(group, Comparator.comparing(this::getScalarWeight).reversed()); map.computeIfAbsent(getMaxWeight(group), __ -> new ArrayList<>()).addAll(group); } return map; }
Example 6
Source File: FileIncludeManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public void processIncludingFiles(PsiFile context, Processor<? super Pair<VirtualFile, FileIncludeInfo>> processor) { context = context.getOriginalFile(); VirtualFile contextFile = context.getVirtualFile(); if (contextFile == null) return; String originalName = context.getName(); Collection<String> names = getPossibleIncludeNames(context, originalName); GlobalSearchScope scope = GlobalSearchScope.allScope(myProject); for (String name : names) { MultiMap<VirtualFile, FileIncludeInfoImpl> infoList = FileIncludeIndex.getIncludingFileCandidates(name, scope); for (VirtualFile candidate : infoList.keySet()) { PsiFile psiFile = myPsiManager.findFile(candidate); if (psiFile == null || context.equals(psiFile)) continue; for (FileIncludeInfo info : infoList.get(candidate)) { PsiFileSystemItem item = resolveFileInclude(info, psiFile); if (item != null && contextFile.equals(item.getVirtualFile())) { if (!processor.process(Pair.create(candidate, info))) { return; } } } } } }
Example 7
Source File: ApplyPatchDefaultExecutor.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull protected Collection<PatchApplier> getPatchAppliers(@Nonnull MultiMap<VirtualFile, AbstractFilePatchInProgress> patchGroups, @Nullable LocalChangeList localList, @Nonnull CommitContext commitContext) { final Collection<PatchApplier> appliers = new LinkedList<>(); for (VirtualFile base : patchGroups.keySet()) { appliers.add(new PatchApplier<BinaryFilePatch>(myProject, base, ContainerUtil .map(patchGroups.get(base), new Function<AbstractFilePatchInProgress, FilePatch>() { @Override public FilePatch fun(AbstractFilePatchInProgress patchInProgress) { return patchInProgress.getPatch(); } }), localList, null, commitContext)); } return appliers; }
Example 8
Source File: GenericInlineHandler.java From consulo with Apache License 2.0 | 6 votes |
public static void collectConflicts(final PsiReference reference, final PsiElement element, final Map<Language, InlineHandler.Inliner> inliners, final MultiMap<PsiElement, String> conflicts) { final PsiElement referenceElement = reference.getElement(); if (referenceElement == null) return; final Language language = referenceElement.getLanguage(); final InlineHandler.Inliner inliner = inliners.get(language); if (inliner != null) { final MultiMap<PsiElement, String> refConflicts = inliner.getConflicts(reference, element); if (refConflicts != null) { for (PsiElement psiElement : refConflicts.keySet()) { conflicts.putValues(psiElement, refConflicts.get(psiElement)); } } } else { conflicts.putValue(referenceElement, "Cannot inline reference from " + language.getID()); } }
Example 9
Source File: ExpandChildrenIndentState.java From consulo with Apache License 2.0 | 6 votes |
private void restoreAlignments(MultiMap<Alignment, LeafBlockWrapper> blocks) { for (Alignment alignment : blocks.keySet()) { AlignmentImpl alignmentImpl = (AlignmentImpl)alignment; if (!alignmentImpl.isAllowBackwardShift()) continue; Set<LeafBlockWrapper> toRealign = alignmentImpl.getOffsetResponsibleBlocks(); arrangeSpaces(toRealign); LeafBlockWrapper rightMostBlock = getRightMostBlock(toRealign); int maxSpacesBeforeBlock = rightMostBlock.getNumberOfSymbolsBeforeBlock().getTotalSpaces(); int rightMostBlockLine = myDocument.getLineNumber(rightMostBlock.getStartOffset()); for (LeafBlockWrapper block : toRealign) { int currentBlockLine = myDocument.getLineNumber(block.getStartOffset()); if (currentBlockLine == rightMostBlockLine) continue; int blockIndent = block.getNumberOfSymbolsBeforeBlock().getTotalSpaces(); int delta = maxSpacesBeforeBlock - blockIndent; if (delta > 0) { int newSpaces = block.getWhiteSpace().getTotalSpaces() + delta; adjustSpacingToKeepAligned(block, newSpaces); } } } }
Example 10
Source File: AttachToProcessActionBase.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull static List<AttachToProcessItem> doCollectAttachProcessItems(@Nonnull final Project project, @Nonnull XAttachHost host, @Nonnull List<? extends ProcessInfo> processInfos, @Nonnull ProgressIndicator indicator, @Nonnull List<? extends XAttachDebuggerProvider> providers) { UserDataHolderBase dataHolder = new UserDataHolderBase(); List<AttachToProcessItem> currentItems = new ArrayList<>(); for (ProcessInfo process : processInfos) { MultiMap<XAttachPresentationGroup<ProcessInfo>, XAttachDebugger> groupsWithDebuggers = new MultiMap<>(); for (XAttachDebuggerProvider provider : providers) { indicator.checkCanceled(); groupsWithDebuggers.putValues(provider.getPresentationGroup(), provider.getAvailableDebuggers(project, host, process, dataHolder)); } for (XAttachPresentationGroup<ProcessInfo> group : groupsWithDebuggers.keySet()) { Collection<XAttachDebugger> debuggers = groupsWithDebuggers.get(group); if (!debuggers.isEmpty()) { currentItems.add(new AttachToProcessItem(group, false, host, process, new ArrayList<>(debuggers), project, dataHolder)); } } } Collections.sort(currentItems); doUpdateFirstInGroup(currentItems); List<AttachToProcessItem> result = getRecentItems(currentItems, host, project, dataHolder); result.addAll(currentItems); return result; }
Example 11
Source File: ProjectLoadingErrorsNotifierImpl.java From consulo with Apache License 2.0 | 5 votes |
private void fireNotifications() { final MultiMap<ConfigurationErrorType, ConfigurationErrorDescription> descriptionsMap = new MultiMap<ConfigurationErrorType, ConfigurationErrorDescription>(); synchronized (myLock) { if (myErrors.isEmpty()) return; descriptionsMap.putAllValues(myErrors); myErrors.clear(); } for (final ConfigurationErrorType type : descriptionsMap.keySet()) { final Collection<ConfigurationErrorDescription> descriptions = descriptionsMap.get(type); if (descriptions.isEmpty()) continue; final String invalidElements = getInvalidElementsString(type, descriptions); final String errorText = ProjectBundle.message("error.message.configuration.cannot.load") + " " + invalidElements + " <a href=\"\">Details...</a>"; Notifications.Bus.notify(new Notification("Project Loading Error", "Error Loading Project", errorText, NotificationType.ERROR, new NotificationListener() { @Override public void hyperlinkUpdate(@Nonnull Notification notification, @Nonnull HyperlinkEvent event) { final List<ConfigurationErrorDescription> validDescriptions = ContainerUtil.findAll(descriptions, new Condition<ConfigurationErrorDescription>() { @Override public boolean value(ConfigurationErrorDescription errorDescription) { return errorDescription.isValid(); } }); RemoveInvalidElementsDialog.showDialog(myProject, CommonBundle.getErrorTitle(), type, invalidElements, validDescriptions); notification.expire(); } }), myProject); } }
Example 12
Source File: CompletionLookupArrangerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override public Map<LookupElement, List<Pair<String, Object>>> getRelevanceObjects(@Nonnull Iterable<LookupElement> items, boolean hideSingleValued) { Map<LookupElement, List<Pair<String, Object>>> map = ContainerUtil.newIdentityHashMap(); MultiMap<CompletionSorterImpl, LookupElement> inputBySorter = groupItemsBySorter(items); int sorterNumber = 0; for (CompletionSorterImpl sorter : inputBySorter.keySet()) { sorterNumber++; Collection<LookupElement> thisSorterItems = inputBySorter.get(sorter); for (LookupElement element : thisSorterItems) { map.put(element, ContainerUtil.newArrayList(new Pair<>("frozen", myFrozenItems.contains(element)), new Pair<>("sorter", sorterNumber))); } ProcessingContext context = createContext(); Classifier<LookupElement> classifier = myClassifiers.get(sorter); while (classifier != null) { final THashSet<LookupElement> itemSet = ContainerUtil.newIdentityTroveSet(thisSorterItems); List<LookupElement> unsortedItems = ContainerUtil.filter(myItems, lookupElement -> itemSet.contains(lookupElement)); List<Pair<LookupElement, Object>> pairs = classifier.getSortingWeights(unsortedItems, context); if (!hideSingleValued || !haveSameWeights(pairs)) { for (Pair<LookupElement, Object> pair : pairs) { map.get(pair.first).add(Pair.create(classifier.getPresentableName(), pair.second)); } } classifier = classifier.getNext(); } } //noinspection unchecked Map<LookupElement, List<Pair<String, Object>>> result = new com.intellij.util.containers.hash.LinkedHashMap(EqualityPolicy.IDENTITY); Map<LookupElement, List<Pair<String, Object>>> additional = myFinalSorter.getRelevanceObjects(items); for (LookupElement item : items) { List<Pair<String, Object>> mainRelevance = map.get(item); List<Pair<String, Object>> additionalRelevance = additional.get(item); result.put(item, additionalRelevance == null ? mainRelevance : ContainerUtil.concat(mainRelevance, additionalRelevance)); } return result; }
Example 13
Source File: CompletionLookupArrangerImpl.java From consulo with Apache License 2.0 | 5 votes |
private MultiMap<CompletionSorterImpl, LookupElement> groupItemsBySorter(Iterable<? extends LookupElement> source) { MultiMap<CompletionSorterImpl, LookupElement> inputBySorter = MultiMap.createLinked(); for (LookupElement element : source) { inputBySorter.putValue(obtainSorter(element), element); } for (CompletionSorterImpl sorter : inputBySorter.keySet()) { inputBySorter.put(sorter, sortByPresentation(inputBySorter.get(sorter))); } return inputBySorter; }
Example 14
Source File: TriggerAdditionOrDeletion.java From consulo with Apache License 2.0 | 5 votes |
private void processDeletion(SortByVcsRoots<FilePath> sortByVcsRoots) { final MultiMap<VcsRoot, FilePath> map = sortByVcsRoots.sort(myDeleted); myPreparedDeletion = new MultiMap<>(); for (VcsRoot vcsRoot : map.keySet()) { if (vcsRoot != null && vcsRoot.getVcs() != null) { final CheckinEnvironment localChangesProvider = vcsRoot.getVcs().getCheckinEnvironment(); if (localChangesProvider == null) continue; final boolean takeDirs = vcsRoot.getVcs().areDirectoriesVersionedItems(); final Collection<FilePath> files = map.get(vcsRoot); final List<FilePath> toBeDeleted = new LinkedList<>(); for (FilePath file : files) { final FilePath parent = file.getParentPath(); if ((takeDirs || (! file.isDirectory())) && parent != null && parent.getIOFile().exists()) { toBeDeleted.add(file); } } if (toBeDeleted.isEmpty()) return; if (! vcsRoot.getVcs().fileListenerIsSynchronous()) { for (FilePath filePath : toBeDeleted) { myVcsFileListenerContextHelper.ignoreDeleted(filePath); } } myPreparedDeletion.put(vcsRoot, toBeDeleted); } } }
Example 15
Source File: Unity3dSceneReferenceSearcher.java From consulo-unity3d with Apache License 2.0 | 5 votes |
@Override public void processQuery(@Nonnull ReferencesSearch.SearchParameters searchParameters, @Nonnull Processor<? super PsiReference> processor) { SearchScope scope = ReadAction.compute(searchParameters::getEffectiveSearchScope); if(!(scope instanceof GlobalSearchScope)) { return; } Project project = searchParameters.getProject(); PsiElement element = searchParameters.getElementToSearch(); if(ReadAction.compute(() -> Unity3dModuleExtensionUtil.getRootModule(searchParameters.getProject()) != null)) { if(element instanceof CSharpFieldDeclaration) { String name = ReadAction.compute(((CSharpFieldDeclaration) element)::getName); MultiMap<VirtualFile, Unity3dYMLAsset> map = ReadAction.compute(() -> Unity3dYMLAsset.findAssetAsAttach(project, PsiUtilCore.getVirtualFile(element))); for(VirtualFile virtualFile : map.keySet()) { ProgressManager.checkCanceled(); searchParameters.getOptimizer().searchWord(name + ":", GlobalSearchScope.fileScope(project, virtualFile), true, element); } } else if(element instanceof YAMLFile) { String guid = ReadAction.compute(() -> Unity3dMetaManager.getInstance(project).getGUID(PsiUtilCore.getVirtualFile(element))); if(guid != null) { searchParameters.getOptimizer().searchWord(guid, GlobalSearchScope.allScope(project), true, element); } } } }
Example 16
Source File: IdeaTextPatchBuilder.java From consulo with Apache License 2.0 | 5 votes |
public static List<BeforeAfter<AirContentRevision>> revisionsConvertor(final Project project, final List<Change> changes) throws VcsException { final List<BeforeAfter<AirContentRevision>> result = new ArrayList<BeforeAfter<AirContentRevision>>(changes.size()); final Convertor<Change, FilePath> beforePrefferingConvertor = new Convertor<Change, FilePath>() { @Override public FilePath convert(Change o) { final FilePath before = ChangesUtil.getBeforePath(o); return before == null ? ChangesUtil.getAfterPath(o) : before; } }; final MultiMap<VcsRoot,Change> byRoots = new SortByVcsRoots<Change>(project, beforePrefferingConvertor).sort(changes); for (VcsRoot root : byRoots.keySet()) { final Collection<Change> rootChanges = byRoots.get(root); if (root.getVcs() == null || root.getVcs().getOutgoingChangesProvider() == null) { addConvertChanges(rootChanges, result); continue; } final VcsOutgoingChangesProvider<?> provider = root.getVcs().getOutgoingChangesProvider(); final Collection<Change> basedOnLocal = provider.filterLocalChangesBasedOnLocalCommits(rootChanges, root.getPath()); rootChanges.removeAll(basedOnLocal); addConvertChanges(rootChanges, result); for (Change change : basedOnLocal) { // dates are here instead of numbers result.add(new BeforeAfter<AirContentRevision>(convertRevision(change.getBeforeRevision(), provider), convertRevision(change.getAfterRevision(), provider))); } } return result; }
Example 17
Source File: VcsLogUserFilterTest.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private List<VcsCommitMetadata> generateMetadata(@Nonnull MultiMap<VcsUser, String> commits) { List<VcsCommitMetadata> result = ContainerUtil.newArrayList(); for (VcsUser user : commits.keySet()) { for (String commit : commits.get(user)) { result.add(myObjectsFactory.createCommitMetadata(HashImpl.build(commit), emptyList(), System.currentTimeMillis(), myProject.getBaseDir(), "subject " + Math.random(), user.getName(), user.getEmail(), "message " + Math.random(), user.getName(), user.getEmail(), System.currentTimeMillis())); } } return result; }
Example 18
Source File: VcsLogUserFilterTest.java From consulo with Apache License 2.0 | 5 votes |
public void testJeka() throws Exception { VcsUser jeka = myObjectsFactory.createUser("User Userovich", "[email protected]"); List<VcsUser> users = Arrays.asList(jeka, myObjectsFactory.createUser("Auser Auserovich", "[email protected]"), myObjectsFactory.createUser("Buser Buserovich", "[email protected]"), myObjectsFactory.createUser("Cuser cuserovich", "[email protected]")); MultiMap<VcsUser, String> commits = generateHistory(users); List<VcsCommitMetadata> metadata = generateMetadata(commits); StringBuilder builder = new StringBuilder(); VcsLogUserFilter userFilter = new VcsLogUserFilterImpl(singleton("jeka"), emptyMap(), commits.keySet()); checkFilter(userFilter, "jeka", commits.get(jeka), metadata, builder); assertFilteredCorrectly(builder); }
Example 19
Source File: VcsLogUserFilterTest.java From consulo with Apache License 2.0 | 5 votes |
public void testWeirdNames() throws Exception { MultiMap<VcsUser, String> commits = generateHistory("User [company]", "[email protected]", "Userovich, User", "[email protected]", "User (user)", "[email protected]"); List<VcsCommitMetadata> metadata = generateMetadata(commits); StringBuilder builder = new StringBuilder(); for (VcsUser user : commits.keySet()) { checkFilterForUser(user, commits.keySet(), commits.get(user), metadata, builder); } assertFilteredCorrectly(builder); }
Example 20
Source File: CompileDriver.java From consulo with Apache License 2.0 | 5 votes |
private void clearAffectedOutputPathsIfPossible(final CompileContextEx context) { ThrowableComputable<List<File>, RuntimeException> action = () -> { final MultiMap<File, Module> outputToModulesMap = new MultiMap<>(); for (Module module : ModuleManager.getInstance(myProject).getModules()) { ModuleCompilerPathsManager moduleCompilerPathsManager = ModuleCompilerPathsManager.getInstance(module); for (ContentFolderTypeProvider contentFolderTypeProvider : ContentFolderTypeProvider.filter(ContentFolderScopes.productionAndTest())) { final String outputPathUrl = moduleCompilerPathsManager.getCompilerOutputUrl(contentFolderTypeProvider); if (outputPathUrl != null) { final String path = VirtualFileManager.extractPath(outputPathUrl); outputToModulesMap.putValue(new File(path), module); } } } final Set<Module> affectedModules = new HashSet<>(Arrays.asList(context.getCompileScope().getAffectedModules())); List<File> result = new ArrayList<>(affectedModules.size() * 2); for (File output : outputToModulesMap.keySet()) { if (affectedModules.containsAll(outputToModulesMap.get(output))) { result.add(output); } } final Set<Artifact> artifactsToBuild = ArtifactCompileScope.getArtifactsToBuild(myProject, context.getCompileScope(), true); for (Artifact artifact : artifactsToBuild) { final String outputFilePath = ((ArtifactImpl)artifact).getOutputDirectoryPathToCleanOnRebuild(); if (outputFilePath != null) { result.add(new File(FileUtil.toSystemDependentName(outputFilePath))); } } return result; }; final List<File> scopeOutputs = AccessRule.read(action); if (scopeOutputs.size() > 0) { CompilerUtil.runInContext(context, CompilerBundle.message("progress.clearing.output"), () -> CompilerUtil.clearOutputDirectories(scopeOutputs)); } }