Java Code Examples for com.intellij.util.containers.ContainerUtil#newHashMap()

The following examples show how to use com.intellij.util.containers.ContainerUtil#newHashMap() . 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: VcsRepositoryManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private Map<VirtualFile, Repository> findNewRoots(@Nonnull Set<VirtualFile> knownRoots) {
  Map<VirtualFile, Repository> newRootsMap = ContainerUtil.newHashMap();
  for (VcsRoot root : myVcsManager.getAllVcsRoots()) {
    VirtualFile rootPath = root.getPath();
    if (rootPath != null && !knownRoots.contains(rootPath)) {
      AbstractVcs vcs = root.getVcs();
      VcsRepositoryCreator repositoryCreator = getRepositoryCreator(vcs);
      if (repositoryCreator == null) continue;
      Repository repository = repositoryCreator.createRepositoryIfValid(rootPath);
      if (repository != null) {
        newRootsMap.put(rootPath, repository);
      }
    }
  }
  return newRootsMap;
}
 
Example 2
Source File: VcsStructureChooser.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private Map<VirtualFile, String> calculateModules(@Nonnull List<VirtualFile> roots) {
  Map<VirtualFile, String> result = ContainerUtil.newHashMap();

  final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
  // assertion for read access inside
  Module[] modules = ApplicationManager.getApplication().runReadAction(new Computable<Module[]>() {
    public Module[] compute() {
      return moduleManager.getModules();
    }
  });

  TreeSet<VirtualFile> checkSet = new TreeSet<>(FilePathComparator.getInstance());
  checkSet.addAll(roots);
  for (Module module : modules) {
    VirtualFile[] files = ModuleRootManager.getInstance(module).getContentRoots();
    for (VirtualFile file : files) {
      VirtualFile floor = checkSet.floor(file);
      if (floor != null) {
        result.put(file, module.getName());
      }
    }
  }
  return result;
}
 
Example 3
Source File: FakeVisiblePackBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
private RefsModel createRefsModel(@Nonnull RefsModel refsModel,
                                  @Nonnull Set<Integer> heads,
                                  @Nonnull VisibleGraph<Integer> visibleGraph,
                                  @Nonnull Map<VirtualFile, VcsLogProvider> providers) {
  Set<VcsRef> branchesAndHeads = ContainerUtil.newHashSet();
  refsModel.getBranches().stream().filter(ref -> {
    int index = myHashMap.getCommitIndex(ref.getCommitHash(), ref.getRoot());
    Integer row = visibleGraph.getVisibleRowIndex(index);
    return row != null && row >= 0;
  }).forEach(branchesAndHeads::add);
  heads.stream().flatMap(head -> refsModel.refsToCommit(head).stream()).forEach(branchesAndHeads::add);

  Map<VirtualFile, Set<VcsRef>> map = VcsLogUtil.groupRefsByRoot(branchesAndHeads);
  Map<VirtualFile, CompressedRefs> refs = ContainerUtil.newHashMap();
  for (VirtualFile root : providers.keySet()) {
    Set<VcsRef> refsForRoot = map.get(root);
    refs.put(root, new CompressedRefs(refsForRoot == null ? ContainerUtil.newHashSet() : refsForRoot, myHashMap));
  }
  return new RefsModel(refs, heads, myHashMap, providers);
}
 
Example 4
Source File: VcsLogManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static Map<VirtualFile, VcsLogProvider> findLogProviders(@Nonnull Collection<VcsRoot> roots, @Nonnull Project project) {
  Map<VirtualFile, VcsLogProvider> logProviders = ContainerUtil.newHashMap();
  VcsLogProvider[] allLogProviders = Extensions.getExtensions(LOG_PROVIDER_EP, project);
  for (VcsRoot root : roots) {
    AbstractVcs vcs = root.getVcs();
    VirtualFile path = root.getPath();
    if (vcs == null || path == null) {
      LOG.error("Skipping invalid VCS root: " + root);
      continue;
    }

    for (VcsLogProvider provider : allLogProviders) {
      if (provider.getSupportedVcs().equals(vcs.getKeyInstanceMethod())) {
        logProviders.put(path, provider);
        break;
      }
    }
  }
  return logProviders;
}
 
Example 5
Source File: SimpleCoverageAnnotator.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void annotate(@Nonnull final VirtualFile contentRoot,
                     @Nonnull final CoverageSuitesBundle suite,
                     final @Nonnull CoverageDataManager dataManager, @Nonnull final ProjectData data,
                     final Project project,
                     final Annotator annotator)
{
  if (!contentRoot.isValid()) {
    return;
  }

  // TODO: check name filter!!!!!

  final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();

  @SuppressWarnings("unchecked") final Set<String> files = data.getClasses().keySet();
  final Map<String, String> normalizedFiles2Files = ContainerUtil.newHashMap();
  for (final String file : files) {
    normalizedFiles2Files.put(normalizeFilePath(file), file);
  }
  collectFolderCoverage(contentRoot, dataManager, annotator, data,
                        suite.isTrackTestFolders(),
                        index,
                        suite.getCoverageEngine(),
                        ContainerUtil.<VirtualFile>newHashSet(),
                        Collections.unmodifiableMap(normalizedFiles2Files));
}
 
Example 6
Source File: DvcsUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static <R extends Repository> Map<R, List<VcsFullCommitDetails>> groupCommitsByRoots(@Nonnull RepositoryManager<R> repoManager,
                                                                                            @Nonnull List<? extends VcsFullCommitDetails> commits) {
  Map<R, List<VcsFullCommitDetails>> groupedCommits = ContainerUtil.newHashMap();
  for (VcsFullCommitDetails commit : commits) {
    R repository = repoManager.getRepositoryForRoot(commit.getRoot());
    if (repository == null) {
      LOGGER.info("No repository found for commit " + commit);
      continue;
    }
    List<VcsFullCommitDetails> commitsInRoot = groupedCommits.get(repository);
    if (commitsInRoot == null) {
      commitsInRoot = ContainerUtil.newArrayList();
      groupedCommits.put(repository, commitsInRoot);
    }
    commitsInRoot.add(commit);
  }
  return groupedCommits;
}
 
Example 7
Source File: TFSDiffProvider.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
@Override
public Map<VirtualFile, VcsRevisionNumber> getCurrentRevisions(Iterable<VirtualFile> files) {
    final ServerContext context = TFSVcs.getInstance(project).getServerContext(true);
    final List<String> filePaths = ContainerUtil.newArrayList();
    for (VirtualFile file : files) {
        String filePath = file.getPath();
        filePaths.add(filePath);
    }

    TfvcClient client = TfvcClient.getInstance(project);
    final LocalFileSystem fs = LocalFileSystem.getInstance();
    final Map<VirtualFile, VcsRevisionNumber> revisionMap = ContainerUtil.newHashMap();
    client.getLocalItemsInfo(context, filePaths, info -> {
        final String itemPath = info.getLocalItem();
        final VirtualFile virtualFile = fs.findFileByPath(itemPath);
        if (virtualFile == null) {
            logger.error("VirtualFile not found for item " + itemPath);
            return;
        }

        revisionMap.put(virtualFile, createRevision(info, itemPath));
    });

    return revisionMap;
}
 
Example 8
Source File: TransferableFileEditorStateSupport.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void writeContextData(@Nonnull DiffContext context, @Nonnull TransferableFileEditorState state) {
  Map<String, Map<String, String>> map = context.getUserData(TRANSFERABLE_FILE_EDITOR_STATE);
  if (map == null) {
    map = ContainerUtil.newHashMap();
    context.putUserData(TRANSFERABLE_FILE_EDITOR_STATE, map);
  }

  map.put(state.getEditorId(), state.getTransferableOptions());
}
 
Example 9
Source File: GeneralCommandLine.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public <T> void putUserData(@Nonnull Key<T> key, @Nullable T value) {
  if (myUserData == null) {
    myUserData = ContainerUtil.newHashMap();
  }
  myUserData.put(key, value);
}
 
Example 10
Source File: VcsLogRefresherImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private Map<VirtualFile, CompressedRefs> getAllNewRefs(@Nonnull LogInfo newInfo,
                                                       @Nonnull Map<VirtualFile, CompressedRefs> previousRefs) {
  Map<VirtualFile, CompressedRefs> result = ContainerUtil.newHashMap();
  for (VirtualFile root : previousRefs.keySet()) {
    CompressedRefs newInfoRefs = newInfo.getRefs().get(root);
    result.put(root, newInfoRefs != null ? newInfoRefs : previousRefs.get(root));
  }
  return result;
}
 
Example 11
Source File: WrappingAndBracesPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected SettingsGroup getAssociatedSettingsGroup(String fieldName) {
  if (myFieldNameToGroup == null) {
    myFieldNameToGroup = ContainerUtil.newHashMap();
    Set<String> groups = myGroupToFields.keySet();
    for (String group : groups) {
      Collection<String> fields = myGroupToFields.get(group);
      SettingsGroup settingsGroup = new SettingsGroup(group, fields);
      for (String field : fields) {
        myFieldNameToGroup.put(field, settingsGroup);
      }
    }
  }
  return myFieldNameToGroup.get(fieldName);
}
 
Example 12
Source File: PushController.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private <R extends Repository, S extends PushSource, T extends PushTarget> Map<R, PushSpec<S, T>> collectPushSpecsForVcs(@Nonnull PushSupport<R, S, T> pushSupport) {
  Map<R, PushSpec<S, T>> pushSpecs = ContainerUtil.newHashMap();
  Collection<MyRepoModel<?, ?, ?>> repositoriesInformation = getSelectedRepoNode();
  for (MyRepoModel<?, ?, ?> repoModel : repositoriesInformation) {
    if (pushSupport.equals(repoModel.getSupport())) {
      //todo improve generics: unchecked casts
      T target = (T)repoModel.getTarget();
      if (target != null) {
        pushSpecs.put((R)repoModel.getRepository(), new PushSpec<S, T>((S)repoModel.getSource(), target));
      }
    }
  }
  return pushSpecs;
}
 
Example 13
Source File: DataPack.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static Map<VirtualFile, VcsLogRefManager> getRefManagerMap(@Nonnull Map<VirtualFile, VcsLogProvider> logProviders) {
  Map<VirtualFile, VcsLogRefManager> map = ContainerUtil.newHashMap();
  for (Map.Entry<VirtualFile, VcsLogProvider> entry : logProviders.entrySet()) {
    map.put(entry.getKey(), entry.getValue().getReferenceManager());
  }
  return map;
}
 
Example 14
Source File: VcsLogJoiner.java    From consulo with Apache License 2.0 5 votes vote down vote up
public NewCommitIntegrator(@Nonnull List<Commit> list, @Nonnull Collection<Commit> newCommits) {
  this.list = list;
  newCommitsMap = ContainerUtil.newHashMap();
  for (Commit commit : newCommits) {
    newCommitsMap.put(commit.getId(), commit);
  }
  commitsStack = new Stack<>();
}
 
Example 15
Source File: VetoSavingCommittingDocumentsAdapter.java    From consulo with Apache License 2.0 5 votes vote down vote up
private Map<Document, Project> getDocumentsBeingCommitted() {
  Map<Document, Project> documentsToWarn = ContainerUtil.newHashMap();
  for (Document unsavedDocument : myFileDocumentManager.getUnsavedDocuments()) {
    final Object data = unsavedDocument.getUserData(CommitHelper.DOCUMENT_BEING_COMMITTED_KEY);
    if (data instanceof Project) {
      documentsToWarn.put(unsavedDocument, (Project)data);
    }
  }
  return documentsToWarn;
}
 
Example 16
Source File: ExternalProjectBuildClasspathPojo.java    From consulo with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("UnusedDeclaration")
public ExternalProjectBuildClasspathPojo() {
  // Used by IJ serialization
  this("___DUMMY___", ContainerUtil.<String>newArrayList(), ContainerUtil.<String, ExternalModuleBuildClasspathPojo>newHashMap());
}
 
Example 17
Source File: ShowDiffContext.java    From consulo with Apache License 2.0 4 votes vote down vote up
public <T> void putChainContext(@Nonnull Key<T> key, T value) {
  if (myChainContext == null) myChainContext = ContainerUtil.newHashMap();
  myChainContext.put(key, value);
}
 
Example 18
Source File: FakeVisiblePackBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private RefsModel createEmptyRefsModel() {
  return new RefsModel(ContainerUtil.newHashMap(), ContainerUtil.newHashSet(), myHashMap, ContainerUtil.newHashMap());
}
 
Example 19
Source File: ShowDiffContext.java    From consulo with Apache License 2.0 4 votes vote down vote up
public <T> void putChangeContext(@Nonnull Change change, @Nonnull Key<T> key, T value) {
  if (myRequestContext == null) myRequestContext = ContainerUtil.newHashMap();
  if (!myRequestContext.containsKey(change)) myRequestContext.put(change, ContainerUtil.<Key, Object>newHashMap());
  myRequestContext.get(change).put(key, value);
}
 
Example 20
Source File: StopWatch.java    From consulo with Apache License 2.0 4 votes vote down vote up
private StopWatch(@Nonnull String operation) {
  myOperation = operation;
  myStartTime = System.currentTimeMillis();
  myDurationPerRoot = ContainerUtil.newHashMap();
}