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

The following examples show how to use com.intellij.util.containers.MultiMap#create() . 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: StatisticsWeigher.java    From consulo with Apache License 2.0 6 votes vote down vote up
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 2
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 3
Source File: ReferencesPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ReferencesPanel(LayoutManager layout, int limit) {
  super(layout);
  myRefsLimit = limit;
  myReferences = Collections.emptyList();
  myGroupedVisibleReferences = MultiMap.create();
  setOpaque(false);
}
 
Example 4
Source File: VcsLogRepoSizeCollector.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: VcsLogAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
private MultiMap<Repo, VcsFullCommitDetails> groupByRootWithCheck(@Nonnull Project project, @Nonnull List<VcsFullCommitDetails> commits) {
  MultiMap<Repo, VcsFullCommitDetails> map = MultiMap.create();
  for (VcsFullCommitDetails commit : commits) {
    Repo root = getRepositoryForRoot(project, commit.getRoot());
    if (root == null) { // commit from some other VCS
      return null;
    }
    map.putValue(root, commit);
  }
  return map;
}
 
Example 6
Source File: MacroFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static MultiMap<String, Macro> init() {
  MultiMap<String, Macro> result = MultiMap.create();
  for(Macro macro: Extensions.getExtensions(Macro.EP_NAME)) {
    result.putValue(macro.getName(), macro);
  }
  return result;
}
 
Example 7
Source File: ListTemplatesHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static MultiMap<String, CustomLiveTemplateLookupElement> getCustomTemplatesLookupItems(@Nonnull Editor editor,
                                                                                              @Nonnull PsiFile file,
                                                                                              int offset) {
  final MultiMap<String, CustomLiveTemplateLookupElement> result = MultiMap.create();
  CustomTemplateCallback customTemplateCallback = new CustomTemplateCallback(editor, file);
  for (CustomLiveTemplate customLiveTemplate : TemplateManagerImpl.listApplicableCustomTemplates(editor, file, false)) {
    if (customLiveTemplate instanceof CustomLiveTemplateBase) {
      String customTemplatePrefix = ((CustomLiveTemplateBase)customLiveTemplate).computeTemplateKeyWithoutContextChecking(customTemplateCallback);
      if (customTemplatePrefix != null) {
        result.putValues(customTemplatePrefix, ((CustomLiveTemplateBase)customLiveTemplate).getLookupElements(file, editor, offset));
      }
    }
  }
  return result;
}
 
Example 8
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 9
Source File: MockSdkUtil.java    From intellij with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}