Java Code Examples for com.intellij.util.containers.MultiMap#putValue()
The following examples show how to use
com.intellij.util.containers.MultiMap#putValue() .
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: SemServiceImpl.java From consulo with Apache License 2.0 | 6 votes |
private MultiMap<SemKey, NullableFunction<PsiElement, ? extends SemElement>> collectProducers() { final MultiMap<SemKey, NullableFunction<PsiElement, ? extends SemElement>> map = MultiMap.createSmart(); final SemRegistrar registrar = new SemRegistrar() { @Override public <T extends SemElement, V extends PsiElement> void registerSemElementProvider(SemKey<T> key, final ElementPattern<? extends V> place, final NullableFunction<V, T> provider) { map.putValue(key, element -> { if (place.accepts(element)) { return provider.fun((V)element); } return null; }); } }; for (SemContributorEP contributor : myProject.getExtensions(SemContributor.EP_NAME)) { contributor.registerSemProviders(myProject.getInjectingContainer(), registrar); } return map; }
Example 2
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 3
Source File: DotNetLibraryAnalyzerComponent.java From consulo-csharp with Apache License 2.0 | 6 votes |
private static MultiMap<String, NamespaceReference> buildCache(File key, String libraryName) { try { MultiMap<String, NamespaceReference> map = new MultiMap<String, NamespaceReference>(); TypeDef[] typeDefs = new ModuleParser(key).getTypeDefs(); for(TypeDef typeDef : typeDefs) { String namespace = typeDef.getNamespace(); if(StringUtil.isEmpty(namespace)) { continue; } map.putValue(MsilHelper.cutGenericMarker(typeDef.getName()), new NamespaceReference(namespace, libraryName)); } return map; } catch(IOException | MSILParseException ignored) { } return MultiMap.emptyInstance(); }
Example 4
Source File: CSharpTypeRenamePsiElementProcessor.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Override public void findExistingNameConflicts(PsiElement element, String newName, MultiMap<PsiElement, String> conflicts, Map<PsiElement, String> allRenames) { for(Map.Entry<PsiElement, String> entry : allRenames.entrySet()) { if(entry.getKey() instanceof CSharpFile) { CSharpFile key = (CSharpFile) entry.getKey(); PsiDirectory parent = key.getParent(); if(parent == null) { continue; } PsiFile file = parent.findFile(entry.getValue()); if(file != null) { conflicts.putValue(file, entry.getValue() + " already exists in parent directory"); } } } }
Example 5
Source File: ChangeListWorker.java From consulo with Apache License 2.0 | 6 votes |
@Nullable public MultiMap<LocalChangeList, Change> moveChangesTo(final String name, final Change[] changes) { final LocalChangeListImpl changeList = (LocalChangeListImpl) myMap.get(name); if (changeList != null) { final MultiMap<LocalChangeList, Change> result = new MultiMap<>(); for (LocalChangeList list : myMap.values()) { if (list.equals(changeList)) continue; for (Change change : changes) { final Change removedChange = ((LocalChangeListImpl)list).removeChange(change); if (removedChange != null) { changeList.addChange(removedChange); result.putValue(list, removedChange); } } } return result; } return null; }
Example 6
Source File: InjectedLanguageManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull private ClassMapCachingNulls<MultiHostInjector> calcInjectorMap() { Map<Class<?>, MultiHostInjector[]> injectors = new HashMap<>(); MultiMap<Class<? extends PsiElement>, MultiHostInjector> allInjectors = new MultiMap<>(); for (MultiHostInjectorExtensionPoint extensionPoint : MultiHostInjector.EP_NAME.getExtensionList(myProject)) { allInjectors.putValue(extensionPoint.getKey(), extensionPoint.getInstance(myProject)); } if (LanguageInjector.EXTENSION_POINT_NAME.hasAnyExtensions()) { allInjectors.putValue(PsiLanguageInjectionHost.class, PsiManagerRegisteredInjectorsAdapter.INSTANCE); } for (Map.Entry<Class<? extends PsiElement>, Collection<MultiHostInjector>> injector : allInjectors.entrySet()) { Class<? extends PsiElement> place = injector.getKey(); Collection<MultiHostInjector> value = injector.getValue(); injectors.put(place, value.toArray(new MultiHostInjector[0])); } return new ClassMapCachingNulls<>(injectors, new MultiHostInjector[0], new ArrayList<>(allInjectors.values())); }
Example 7
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 8
Source File: MoveDirectoryWithClassesProcessor.java From consulo with Apache License 2.0 | 6 votes |
@Override protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) { final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>(); for (PsiFile psiFile : myFilesToMove.keySet()) { try { myFilesToMove.get(psiFile).checkMove(psiFile); } catch (IncorrectOperationException e) { conflicts.putValue(psiFile, e.getMessage()); } } for (MoveDirectoryWithClassesHelper helper : MoveDirectoryWithClassesHelper.findAll()) { helper.preprocessUsages(myProject, myFilesToMove.keySet(), refUsages.get(), myTargetDirectory, conflicts); } return showConflicts(conflicts, refUsages.get()); }
Example 9
Source File: VcsLogRepoSizeCollector.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static MultiMap<VcsKey, VirtualFile> groupRootsByVcs(@Nonnull Map<VirtualFile, VcsLogProvider> providers) { MultiMap<VcsKey, VirtualFile> result = MultiMap.create(); for (Map.Entry<VirtualFile, VcsLogProvider> entry : providers.entrySet()) { VirtualFile root = entry.getKey(); VcsKey vcs = entry.getValue().getSupportedVcs(); result.putValue(vcs, root); } return result; }
Example 10
Source File: SortByVcsRoots.java From consulo with Apache License 2.0 | 5 votes |
public MultiMap<VcsRoot, T> sort(final Collection<T> in) { final MultiMap<VcsRoot, T> result = new MultiMap<VcsRoot,T>(); for (T t : in) { final VcsRoot root = myVcsManager.getVcsRootObjectFor(myConvertor.convert(t)); if (root != null) { result.putValue(root, t); } else { result.putValue(ourFictiveValue, t); } } return result; }
Example 11
Source File: ComponentManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
protected void fillListenerDescriptors(MultiMap<String, PluginListenerDescriptor> mapByTopic) { for (PluginDescriptor plugin : PluginManager.getPlugins()) { if (!PluginManagerCore.shouldSkipPlugin(plugin)) { List<PluginListenerDescriptor> descriptors = getPluginListenerDescriptors(plugin); for (PluginListenerDescriptor descriptor : descriptors) { mapByTopic.putValue(descriptor.topicClassName, descriptor); } } } }
Example 12
Source File: DesktopImportantFolderLocker.java From consulo with Apache License 2.0 | 5 votes |
private static void addExistingPort(@Nonnull File portMarker, @Nonnull String path, @Nonnull MultiMap<Integer, String> portToPath) { if (portMarker.exists()) { try { portToPath.putValue(Integer.parseInt(FileUtilRt.loadFile(portMarker)), path); } catch (Exception e) { log(e); // don't delete - we overwrite it on write in any case } } }
Example 13
Source File: PersistentFSImpl.java From consulo with Apache License 2.0 | 5 votes |
private void groupDeletions(@Nonnull List<? extends VFileEvent> events, int start, int end, @Nonnull List<? super VFileEvent> outValidated, @Nonnull List<? super Runnable> outApplyEvents, @Nonnull Set<? extends VFileEvent> toIgnore) { MultiMap<VirtualDirectoryImpl, VFileDeleteEvent> grouped = null; boolean hasValidEvents = false; for (int i = start; i < end; i++) { VFileEvent event = events.get(i); if (!(event instanceof VFileDeleteEvent) || toIgnore.contains(event) || !event.isValid()) continue; VFileDeleteEvent de = (VFileDeleteEvent)event; @Nullable VirtualDirectoryImpl parent = (VirtualDirectoryImpl)de.getFile().getParent(); if (grouped == null) { grouped = new MultiMap<VirtualDirectoryImpl, VFileDeleteEvent>() { @Nonnull @Override protected Map<VirtualDirectoryImpl, Collection<VFileDeleteEvent>> createMap() { return new HashMap<>(end - start); // can be null keys } }; } grouped.putValue(parent, de); outValidated.add(event); hasValidEvents = true; } if (hasValidEvents) { MultiMap<VirtualDirectoryImpl, VFileDeleteEvent> finalGrouped = grouped; outApplyEvents.add((Runnable)() -> { clearIdCache(); applyDeletions(finalGrouped); incStructuralModificationCount(); }); } }
Example 14
Source File: ChangeListWorker.java From consulo with Apache License 2.0 | 5 votes |
private void checkForMultipleCopiesNotMove(boolean somethingChanged) { final MultiMap<FilePath, Pair<Change, String>> moves = new MultiMap<FilePath, Pair<Change, String>>() { @Nonnull protected Collection<Pair<Change, String>> createCollection() { return new LinkedList<>(); } }; for (LocalChangeList changeList : myMap.values()) { final Collection<Change> changes = changeList.getChanges(); for (Change change : changes) { if (change.isMoved() || change.isRenamed()) { moves.putValue(change.getBeforeRevision().getFile(), Pair.create(change, changeList.getName())); } } } for (FilePath filePath : moves.keySet()) { final List<Pair<Change, String>> copies = (List<Pair<Change, String>>) moves.get(filePath); if (copies.size() == 1) continue; copies.sort(MyChangesAfterRevisionComparator.getInstance()); for (int i = 0; i < (copies.size() - 1); i++) { somethingChanged = true; final Pair<Change, String> item = copies.get(i); final Change oldChange = item.getFirst(); final Change newChange = new Change(null, oldChange.getAfterRevision()); final LocalChangeListImpl list = (LocalChangeListImpl) myMap.get(item.getSecond()); list.removeChange(oldChange); list.addChange(newChange); final VcsKey key = myIdx.getVcsFor(oldChange); myIdx.changeRemoved(oldChange); myIdx.changeAdded(newChange, key); } } if (somethingChanged) { FileStatusManager.getInstance(myProject).fileStatusesChanged(); } }
Example 15
Source File: ExtractSuperClassUtil.java From intellij-haxe with Apache License 2.0 | 5 votes |
public static void checkSuperAccessible(PsiDirectory targetDirectory, MultiMap<PsiElement, String> conflicts, final PsiClass subclass) { final VirtualFile virtualFile = subclass.getContainingFile().getVirtualFile(); if (virtualFile != null) { final boolean inTestSourceContent = ProjectRootManager.getInstance(subclass.getProject()).getFileIndex().isInTestSourceContent(virtualFile); final Module module = ModuleUtil.findModuleForFile(virtualFile, subclass.getProject()); if (targetDirectory != null && module != null && !GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, inTestSourceContent).contains(targetDirectory.getVirtualFile())) { conflicts.putValue(subclass, "Superclass won't be accessible in subclass"); } } }
Example 16
Source File: ContentRootPanel.java From consulo with Apache License 2.0 | 5 votes |
protected void addFolderGroupComponents() { final ContentFolder[] contentFolders = getContentEntry().getFolders(ContentFolderScopes.all()); MultiMap<ContentFolderTypeProvider, ContentFolder> folderByType = new MultiMap<ContentFolderTypeProvider, ContentFolder>(); for (ContentFolder folder : contentFolders) { if (folder.isSynthetic()) { continue; } final VirtualFile folderFile = folder.getFile(); if (folderFile != null && isExcludedOrUnderExcludedDirectory(folderFile)) { continue; } folderByType.putValue(folder.getType(), folder); } Insets insets = new Insets(0, 0, 10, 0); GridBagConstraints constraints = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, insets, 0, 0); for (Map.Entry<ContentFolderTypeProvider, Collection<ContentFolder>> entry : folderByType.entrySet()) { Collection<ContentFolder> folders = entry.getValue(); if (folders.isEmpty()) continue; ContentFolderTypeProvider contentFolderTypeProvider = entry.getKey(); ContentFolder[] foldersArray = folders.toArray(new ContentFolder[folders.size()]); final JComponent sourcesComponent = createFolderGroupComponent(contentFolderTypeProvider.getName(), foldersArray, contentFolderTypeProvider.getGroupColor(), contentFolderTypeProvider); add(sourcesComponent, constraints); } }
Example 17
Source File: VcsDirtyScopeManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private MultiMap<AbstractVcs, FilePath> groupByVcs(@Nullable final Collection<FilePath> from) { if (from == null) return MultiMap.empty(); MultiMap<AbstractVcs, FilePath> map = MultiMap.createSet(); for (FilePath path : from) { AbstractVcs vcs = myGuess.getVcsForDirty(path); if (vcs != null) { map.putValue(vcs, path); } } return map; }
Example 18
Source File: VcsLogUserFilterTest.java From consulo with Apache License 2.0 | 4 votes |
private void recordCommit(@Nonnull MultiMap<VcsUser, String> commits, @Nonnull VcsUser user) throws IOException { String commit = commit(user); commits.putValue(user, commit); }
Example 19
Source File: FirstStartCustomizeUtil.java From consulo with Apache License 2.0 | 4 votes |
private static void readPredefinePluginSet(Document document, String setName, MultiMap<String, String> map) { for (Element element : document.getRootElement().getChildren()) { String id = element.getAttributeValue("id"); map.putValue(setName, id); } }
Example 20
Source File: MockSdkUtil.java From intellij with Apache License 2.0 | 3 votes |
/** * Creates a mock SDK and register it in {@link ProjectJdkTable}. * * <p>All dummy files will be created in disks which are used by {@link * com.android.tools.idea.sdk.AndroidSdks#tryToCreate} or {@link * com.android.tools.idea.sdk.IdeSdks#getEligibleAndroidSdks}. It helps {@link ProjectJdkTable} to * make sure a SDK is valid. All sync test with heavy test fixture are recommended to use this * method to improve coverage. * * @param workspace test file system * @param major major version of SDK * @return a mock sdk for the given target and name. The sdk is registered with the {@link * ProjectJdkTable}. */ public static Sdk registerSdk(WorkspaceFileSystem workspace, String major) { String targetHash = String.format(TARGET_HASH, major); MultiMap<OrderRootType, VirtualFile> roots = MultiMap.create(); roots.putValue( OrderRootType.CLASSES, workspace.createFile(new WorkspacePath(PLATFORM_DIR, targetHash + "/android.jar"))); roots.putValue( OrderRootType.CLASSES, workspace.createDirectory(new WorkspacePath(PLATFORM_DIR, targetHash + "/data/res"))); return registerSdk(workspace, major, "0", roots, true); }