Java Code Examples for com.intellij.util.containers.MultiMap#entrySet()

The following examples show how to use com.intellij.util.containers.MultiMap#entrySet() . 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: VcsAnnotationLocalChangesListenerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void processUnderFile(VirtualFile file) {
  final MultiMap<VirtualFile, FileAnnotation> annotations = new MultiMap<>();
  synchronized (myLock) {
    for (VirtualFile virtualFile : myFileAnnotationMap.keySet()) {
      if (VfsUtilCore.isAncestor(file, virtualFile, true)) {
        final Collection<FileAnnotation> values = myFileAnnotationMap.get(virtualFile);
        for (FileAnnotation value : values) {
          annotations.putValue(virtualFile, value);
        }
      }
    }
  }
  if (! annotations.isEmpty()) {
    for (Map.Entry<VirtualFile, Collection<FileAnnotation>> entry : annotations.entrySet()) {
      final VirtualFile key = entry.getKey();
      final VcsRevisionNumber number = fromDiffProvider(key);
      if (number == null) continue;
      final Collection<FileAnnotation> fileAnnotations = entry.getValue();
      for (FileAnnotation annotation : fileAnnotations) {
        if (annotation.isBaseRevisionChanged(number)) {
          annotation.close();
        }
      }
    }
  }
}
 
Example 2
Source File: InjectedLanguageManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: RunAnythingSearchListModel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
protected List<RunAnythingGroup> getGroups() {
  if (myHelpGroups == null) {
    myHelpGroups = new ArrayList<>();
    for (RunAnythingProvider provider : RunAnythingProvider.EP_NAME.getExtensionList()) {
      String helpGroupTitle = provider.getHelpGroupTitle();
      if(helpGroupTitle != null) {

      }
    }

    MultiMap<String, RunAnythingProvider> groupBy = ContainerUtil.groupBy(RunAnythingProvider.EP_NAME.getExtensionList(), RunAnythingProvider::getHelpGroupTitle);

    for (Map.Entry<String, Collection<RunAnythingProvider>> entry : groupBy.entrySet()) {
      myHelpGroups.add(new RunAnythingHelpGroup<>(entry.getKey(), entry.getValue()));
    }

    myHelpGroups.addAll(RunAnythingHelpGroup.EP_NAME.getExtensionList());

  }
  return myHelpGroups;
}
 
Example 4
Source File: WebCoreResourcePathRootsProvider.java    From protobuf-jetbrains-plugin with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public VirtualFile[] getSourceRoots(Module module, ProtoPsiFileRoot psiFileRoot) {
    try {
        if (GET_INSTANCE != null && GET_RESOURCE_ROOTS != null) {
            Object configurationInstance = GET_INSTANCE.invoke(null, module.getProject());
            if (configurationInstance != null) {
                List<VirtualFile> result = new ArrayList<>();
                MultiMap<String, String> resourceRoots = (MultiMap<String, String>) GET_RESOURCE_ROOTS.invoke(configurationInstance);
                for (Map.Entry<String, Collection<String>> entry : resourceRoots.entrySet()) {
                    for (String uri : entry.getValue()) {
                        if (!Strings.isNullOrEmpty(uri) && uri.startsWith("file://")) {
                            String path = uri.substring(7);
                            VirtualFile file = LocalFileSystem.getInstance().findFileByPath(path);
                            if (file != null && file.isDirectory()) {
                                result.add(file);
                            }
                        }
                    }
                }
                return result.toArray(new VirtualFile[0]);
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Could not get source roots for WebCore IDE", e);
    }
    return new VirtualFile[0];
}
 
Example 5
Source File: Unity3dConsoleManager.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
private void pop()
{
	MultiMap<String, UnityLogPostHandlerRequest> map = MultiMap.empty();
	while(!myMessages.isEmpty())
	{
		UnityLogPostHandlerRequest request = myMessages.pollFirst();
		if(request == null)
		{
			continue;
		}

		if(map.isEmpty())
		{
			map = MultiMap.createLinkedSet();
		}

		map.putValue(request.projectPath, request);
	}

	if(map.isEmpty())
	{
		return;
	}

	for(Map.Entry<String, Collection<UnityLogPostHandlerRequest>> entry : map.entrySet())
	{
		Project projectByPath = Unity3dProjectUtil.findProjectByPath(entry.getKey());
		if(projectByPath == null)
		{
			continue;
		}

		Collection<Consumer<Collection<UnityLogPostHandlerRequest>>> consumers = myMap.get(projectByPath);
		for(Consumer<Collection<UnityLogPostHandlerRequest>> consumer : consumers)
		{
			consumer.accept(entry.getValue());
		}
	}
}
 
Example 6
Source File: MapElementGroupCollector.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
@RequiredReadAction
protected Map<K, CSharpElementGroup<E>> compute()
{
	MultiMap<K, E> elements = calcElements();
	final Map<K, CSharpElementGroup<E>> map;
	if(elements.isEmpty())
	{
		map = null;
	}
	else
	{
		map = new LinkedHashMap<>();
		final DotNetGenericExtractor extractor = getExtractor();
		final DotNetModifierListOwner parent = myResolveContext.getElement();
		final Project project = getProject();

		for(Map.Entry<K, Collection<E>> entry : elements.entrySet())
		{
			K key = entry.getKey();
			Collection<E> value = entry.getValue();

			if(extractor != DotNetGenericExtractor.EMPTY)
			{
				value = ContainerUtil.map(value, element -> element instanceof DotNetNamedElement ? (E) GenericUnwrapTool.extract((DotNetNamedElement) element, extractor, parent) : element);
			}

			CSharpElementGroup<E> group = new CSharpElementGroupImpl<>(project, key, value);
			map.put(key, group);
		}
	}

	return map;
}
 
Example 7
Source File: PsiSearchHelperImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void collectFiles(@Nonnull MultiMap<Set<IdIndexEntry>, RequestWithProcessor> singles,
                          @Nonnull ProgressIndicator progress,
                          @Nonnull final MultiMap<VirtualFile, RequestWithProcessor> intersectionResult,
                          @Nonnull final MultiMap<VirtualFile, RequestWithProcessor> restResult) {
  for (Map.Entry<Set<IdIndexEntry>, Collection<RequestWithProcessor>> entry : singles.entrySet()) {
    final Set<IdIndexEntry> keys = entry.getKey();
    if (keys.isEmpty()) {
      continue;
    }

    final Collection<RequestWithProcessor> processors = entry.getValue();
    final GlobalSearchScope commonScope = uniteScopes(processors);
    final Set<VirtualFile> intersectionWithContainerNameFiles = intersectionWithContainerNameFiles(commonScope, processors, keys);

    List<VirtualFile> result = new ArrayList<>();
    Processor<VirtualFile> processor = Processors.cancelableCollectProcessor(result);
    processFilesContainingAllKeys(myManager.getProject(), commonScope, null, keys, processor);
    for (final VirtualFile file : result) {
      progress.checkCanceled();
      for (final IdIndexEntry indexEntry : keys) {
        myDumbService.runReadActionInSmartMode(
                () -> FileBasedIndex.getInstance().processValues(IdIndex.NAME, indexEntry, file, (file1, value) -> {
                  int mask = value.intValue();
                  for (RequestWithProcessor single : processors) {
                    final PsiSearchRequest request = single.request;
                    if ((mask & request.searchContext) != 0 && request.searchScope.contains(file1)) {
                      MultiMap<VirtualFile, RequestWithProcessor> result1 =
                              intersectionWithContainerNameFiles == null || !intersectionWithContainerNameFiles.contains(file1) ? restResult : intersectionResult;
                      result1.putValue(file1, single);
                    }
                  }
                  return true;
                }, commonScope));
      }
    }
  }
}
 
Example 8
Source File: AbstractDataGetter.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public TIntObjectHashMap<T> preLoadCommitData(@Nonnull TIntHashSet commits) throws VcsException {
  TIntObjectHashMap<T> result = new TIntObjectHashMap<>();
  final MultiMap<VirtualFile, String> rootsAndHashes = MultiMap.create();
  commits.forEach(commit -> {
    CommitId commitId = myHashMap.getCommitId(commit);
    if (commitId != null) {
      rootsAndHashes.putValue(commitId.getRoot(), commitId.getHash().asString());
    }
    return true;
  });

  for (Map.Entry<VirtualFile, Collection<String>> entry : rootsAndHashes.entrySet()) {
    VcsLogProvider logProvider = myLogProviders.get(entry.getKey());
    if (logProvider != null) {
      List<? extends T> details = readDetails(logProvider, entry.getKey(), ContainerUtil.newArrayList(entry.getValue()));
      for (T data : details) {
        int index = myHashMap.getCommitIndex(data.getId(), data.getRoot());
        result.put(index, data);
      }
      saveInCache(result);
    }
    else {
      LOG.error("No log provider for root " + entry.getKey().getPath() + ". All known log providers " + myLogProviders);
    }
  }

  return result;
}
 
Example 9
Source File: SimpleRefGroup.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void buildGroups(@Nonnull MultiMap<VcsRefType, VcsRef> groupedRefs,
                               boolean compact,
                               boolean showTagNames,
                               @Nonnull List<RefGroup> result) {
  if (groupedRefs.isEmpty()) return;

  if (compact) {
    VcsRef firstRef = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(groupedRefs.values()));
    RefGroup group = ContainerUtil.getFirstItem(result);
    if (group == null) {
      result.add(new SimpleRefGroup(firstRef.getType().isBranch() || showTagNames ? firstRef.getName() : "",
                                    ContainerUtil.newArrayList(groupedRefs.values())));
    }
    else {
      group.getRefs().addAll(groupedRefs.values());
    }
  }
  else {
    for (Map.Entry<VcsRefType, Collection<VcsRef>> entry : groupedRefs.entrySet()) {
      if (entry.getKey().isBranch()) {
        for (VcsRef ref : entry.getValue()) {
          result.add(new SimpleRefGroup(ref.getName(), ContainerUtil.newArrayList(ref)));
        }
      }
      else {
        result.add(new SimpleRefGroup(showTagNames ? ObjectUtils.notNull(ContainerUtil.getFirstItem(entry.getValue())).getName() : "",
                                      ContainerUtil.newArrayList(entry.getValue())));
      }
    }
  }
}
 
Example 10
Source File: PersistentFSImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void applyDeletions(@Nonnull MultiMap<VirtualDirectoryImpl, VFileDeleteEvent> deletions) {
  for (Map.Entry<VirtualDirectoryImpl, Collection<VFileDeleteEvent>> entry : deletions.entrySet()) {
    VirtualDirectoryImpl parent = entry.getKey();
    Collection<VFileDeleteEvent> deleteEvents = entry.getValue();
    // no valid containing directory, apply events the old way - one by one
    if (parent == null || !parent.isValid()) {
      deleteEvents.forEach(this::applyEvent);
      return;
    }

    int parentId = getFileId(parent);
    int[] oldIds = FSRecords.list(parentId);
    TIntHashSet parentChildrenIds = new TIntHashSet(oldIds);

    List<CharSequence> childrenNamesDeleted = new ArrayList<>(deleteEvents.size());
    TIntHashSet childrenIdsDeleted = new TIntHashSet(deleteEvents.size());

    for (VFileDeleteEvent event : deleteEvents) {
      VirtualFile file = event.getFile();
      int id = getFileId(file);
      childrenNamesDeleted.add(file.getNameSequence());
      childrenIdsDeleted.add(id);
      FSRecords.deleteRecordRecursively(id);
      invalidateSubtree(file);
      parentChildrenIds.remove(id);
    }
    FSRecords.updateList(parentId, parentChildrenIds.toArray());
    parent.removeChildren(childrenIdsDeleted, childrenNamesDeleted);
  }
}
 
Example 11
Source File: PersistentFSImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void applyCreations(@Nonnull MultiMap<VirtualDirectoryImpl, VFileCreateEvent> creations) {
  for (Map.Entry<VirtualDirectoryImpl, Collection<VFileCreateEvent>> entry : creations.entrySet()) {
    VirtualDirectoryImpl parent = entry.getKey();
    Collection<VFileCreateEvent> createEvents = entry.getValue();
    applyCreateEventsInDirectory(parent, createEvents);
  }
}
 
Example 12
Source File: VirtualFilePointerManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void collectNodes(@Nonnull MultiMap<VirtualFilePointerListener, FilePointerPartNode> nodes, @Nonnull MultiMap<VirtualFilePointerListener, FilePointerPartNode> toUpdateUrl) {
  for (Map.Entry<VirtualFilePointerListener, Collection<FilePointerPartNode>> entry : nodes.entrySet()) {
    VirtualFilePointerListener listener = entry.getKey();
    Collection<FilePointerPartNode> values = entry.getValue();
    for (FilePointerPartNode node : values) {
      VirtualFilePointerImpl pointer = node.getAnyPointer();
      if (pointer != null) {
        VirtualFile file = pointer.getFile();
        if (file != null) {
          toUpdateUrl.putValue(listener, node);
        }
      }
    }
  }
}
 
Example 13
Source File: VcsLogOneCommitPerRepoAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
private Map<Repo, VcsFullCommitDetails> convertToSingleElementMap(@Nonnull MultiMap<Repo, VcsFullCommitDetails> groupedCommits) {
  Map<Repo, VcsFullCommitDetails> map = ContainerUtil.newHashMap();
  for (Map.Entry<Repo, Collection<VcsFullCommitDetails>> entry : groupedCommits.entrySet()) {
    Collection<VcsFullCommitDetails> commits = entry.getValue();
    if (commits.size() != 1) {
      return null;
    }
    map.put(entry.getKey(), commits.iterator().next());
  }
  return map;
}
 
Example 14
Source File: ContentRootPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
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 15
Source File: CSharpCompositeTypeDeclaration.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@RequiredReadAction
public static Collection<PsiElement> wrapPartialTypes(@Nonnull GlobalSearchScope scope, @Nonnull Project project, @Nonnull Collection<PsiElement> elements)
{
	MultiMap<String, CSharpTypeDeclaration> partialTypes = null;

	List<PsiElement> newElementList = null;

	PsiElement[] psiElements = ContainerUtil.toArray(elements, PsiElement.ARRAY_FACTORY);

	for(int i = 0; i < psiElements.length; i++)
	{
		ProgressManager.checkCanceled();

		PsiElement psiElement = psiElements[i];
		if(psiElement instanceof CSharpTypeDeclaration && ((CSharpTypeDeclaration) psiElement).hasModifier(CSharpModifier.PARTIAL))
		{
			String vmQName = ((CSharpTypeDeclaration) psiElement).getVmQName();
			if(vmQName != null)
			{
				if(partialTypes == null)
				{
					partialTypes = MultiMap.create();
				}

				if(newElementList == null)
				{
					newElementList = new ArrayList<>(psiElements.length);
					// we need copy head to new list
					newElementList.addAll(Arrays.asList(psiElements).subList(0, i));
				}

				partialTypes.putValue(vmQName, (CSharpTypeDeclaration) psiElement);
				continue;
			}
		}

		if(newElementList != null)
		{
			newElementList.add(psiElement);
		}
	}

	if(partialTypes == null)
	{
		return elements;
	}

	for(Map.Entry<String, Collection<CSharpTypeDeclaration>> entry : partialTypes.entrySet())
	{
		ProgressManager.checkCanceled();

		Collection<CSharpTypeDeclaration> value = entry.getValue();
		// partial modifier is useless, only one class with name
		if(value.size() == 1)
		{
			newElementList.add(value.iterator().next());
		}
		else
		{
			CSharpTypeDeclaration compositeType = CSharpPartialElementManager.getInstance(project).getOrCreateCompositeType(scope, entry.getKey(), value);

			newElementList.add(compositeType);
		}
	}
	return newElementList;
}
 
Example 16
Source File: PersistentFSImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void groupCreations(@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, VFileCreateEvent> grouped = null;

  for (int i = start; i < end; i++) {
    VFileEvent e = events.get(i);
    if (!(e instanceof VFileCreateEvent) || toIgnore.contains(e)) continue;
    VFileCreateEvent event = (VFileCreateEvent)e;
    VirtualDirectoryImpl parent = (VirtualDirectoryImpl)event.getParent();
    if (grouped == null) {
      grouped = new MultiMap<VirtualDirectoryImpl, VFileCreateEvent>() {
        @Nonnull
        @Override
        protected Map<VirtualDirectoryImpl, Collection<VFileCreateEvent>> createMap() {
          return new THashMap<>(end - start);
        }
      };
    }
    grouped.putValue(parent, event);
  }
  if (grouped != null) {
    // since the VCreateEvent.isValid() is extremely expensive, combine all creation events for the directory together
    // and use VirtualDirectoryImpl.validateChildrenToCreate() optimised for bulk validation
    boolean hasValidEvents = false;
    for (Map.Entry<VirtualDirectoryImpl, Collection<VFileCreateEvent>> entry : grouped.entrySet()) {
      VirtualDirectoryImpl directory = entry.getKey();
      List<VFileCreateEvent> createEvents = (List<VFileCreateEvent>)entry.getValue();
      directory.validateChildrenToCreate(createEvents);
      hasValidEvents |= !createEvents.isEmpty();
      outValidated.addAll(createEvents);
    }

    if (hasValidEvents) {
      MultiMap<VirtualDirectoryImpl, VFileCreateEvent> finalGrouped = grouped;
      outApplyEvents.add((Runnable)() -> {
        applyCreations(finalGrouped);
        incStructuralModificationCount();
      });
    }
  }
}