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

The following examples show how to use com.intellij.util.containers.MultiMap#get() . 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: AndroidUtils.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void enableCoeditIfAddToAppDetected(@NotNull Project project) {
  if (isCoeditTransformedProject(project)) {
    return;
  }
  // After a Gradle sync has finished we check the tasks that were run to see if any belong to Flutter.
  Map<ProjectData, MultiMap<String, String>> tasks = getTasksMap(project);
  @NotNull String projectName = project.getName();
  for (ProjectData projectData : tasks.keySet()) {
    MultiMap<String, String> map = tasks.get(projectData);
    Collection<String> col = map.get(FLUTTER_PROJECT_NAME);
    if (col.isEmpty()) {
      col = map.get(""); // Android Studio uses this.
    }
    if (!col.isEmpty()) {
      if (col.parallelStream().anyMatch((x) -> x.startsWith(FLUTTER_TASK_PREFIX))) {
        ApplicationManager.getApplication().invokeLater(() -> enableCoEditing(project));
      }
    }
  }
}
 
Example 2
Source File: AndroidUtils.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void enableCoeditIfAddToAppDetected(@NotNull Project project) {
  if (isCoeditTransformedProject(project)) {
    return;
  }
  // After a Gradle sync has finished we check the tasks that were run to see if any belong to Flutter.
  Map<ProjectData, MultiMap<String, String>> tasks = getTasksMap(project);
  @NotNull String projectName = project.getName();
  for (ProjectData projectData : tasks.keySet()) {
    MultiMap<String, String> map = tasks.get(projectData);
    Collection<String> col = map.get(FLUTTER_PROJECT_NAME);
    if (col.isEmpty()) {
      col = map.get(""); // Android Studio uses this.
    }
    if (!col.isEmpty()) {
      if (col.parallelStream().anyMatch((x) -> x.startsWith(FLUTTER_TASK_PREFIX))) {
        ApplicationManager.getApplication().invokeLater(() -> enableCoEditing(project));
      }
    }
  }
}
 
Example 3
Source File: ChooseComponentsToExportDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean addToExistingListElement(ExportSettingsAction.ExportableItem component,
                                                Map<ExportSettingsAction.ExportableItem, ComponentElementProperties> componentToContainingListElement,
                                                MultiMap<File, ExportSettingsAction.ExportableItem> fileToComponents) {
  final File[] exportFiles = component.getExportFiles();
  File file = null;
  for (File exportFile : exportFiles) {
    Collection<ExportSettingsAction.ExportableItem> tiedComponents = fileToComponents.get(exportFile);

    for (ExportSettingsAction.ExportableItem tiedComponent : tiedComponents) {
      if (tiedComponent == component) continue;
      final ComponentElementProperties elementProperties = componentToContainingListElement.get(tiedComponent);
      if (elementProperties != null && !FileUtil.filesEqual(exportFile, file)) {
        LOG.assertTrue(file == null, "Component " + component + " serialize itself into " + file + " and " + exportFile);
        // found
        elementProperties.addComponent(component);
        componentToContainingListElement.put(component, elementProperties);
        file = exportFile;
      }
    }
  }
  return file != null;
}
 
Example 4
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 5
Source File: LiveTemplateSettingsEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void addContextNode(MultiMap<TemplateContextType, TemplateContextType> hierarchy,
                            CheckedTreeNode parent,
                            TemplateContextType type) {
  final Collection<TemplateContextType> children = hierarchy.get(type);
  final String name = UIUtil.removeMnemonic(type.getPresentableName());
  final CheckedTreeNode node = new CheckedTreeNode(Pair.create(children.isEmpty() ? type : null, name));
  parent.add(node);

  if (children.isEmpty()) {
    node.setChecked(myContext.get(type));
  }
  else {
    for (TemplateContextType child : children) {
      addContextNode(hierarchy, node, child);
    }
    final CheckedTreeNode other = new CheckedTreeNode(Pair.create(type, "Other"));
    other.setChecked(myContext.get(type));
    node.add(other);
  }
}
 
Example 6
Source File: FileIncludeManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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: VcsLogUserFilterTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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 8
Source File: IdeaTextPatchBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
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 9
Source File: AttachToProcessActionBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: VcsDirtyScopeManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void markDirty(@Nonnull DirtBuilder dirtBuilder,
                              @Nonnull MultiMap<AbstractVcs, FilePath> filesOrDirs,
                              boolean recursively) {
  for (AbstractVcs vcs : filesOrDirs.keySet()) {
    for (FilePath path : filesOrDirs.get(vcs)) {
      if (recursively) {
        dirtBuilder.addDirtyDirRecursively(vcs, path);
      }
      else {
        dirtBuilder.addDirtyFile(vcs, path);
      }
    }
  }
}
 
Example 11
Source File: ChangeListWorker.java    From consulo with Apache License 2.0 5 votes vote down vote up
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 12
Source File: TriggerAdditionOrDeletion.java    From consulo with Apache License 2.0 5 votes vote down vote up
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 13
Source File: CompletionLookupArrangerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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 14
Source File: ProjectLoadingErrorsNotifierImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
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);
  }

}