Search in sources :

Example 56 with MultiMap

use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.

the class AbstractDataGetter method preLoadCommitData.

@NotNull
public TIntObjectHashMap<T> preLoadCommitData(@NotNull TIntHashSet commits) throws VcsException {
    TIntObjectHashMap<T> result = new TIntObjectHashMap<>();
    final MultiMap<VirtualFile, String> rootsAndHashes = MultiMap.create();
    commits.forEach(commit -> {
        CommitId commitId = myStorage.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 = myStorage.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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CommitId(com.intellij.vcs.log.CommitId) VcsLogProvider(com.intellij.vcs.log.VcsLogProvider) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) Collection(java.util.Collection) Map(java.util.Map) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) MultiMap(com.intellij.util.containers.MultiMap) TIntIntHashMap(gnu.trove.TIntIntHashMap) NotNull(org.jetbrains.annotations.NotNull)

Example 57 with MultiMap

use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.

the class SimpleRefGroup method buildGroups.

public static void buildGroups(@NotNull MultiMap<VcsRefType, VcsRef> groupedRefs, boolean compact, boolean showTagNames, @NotNull 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())));
            }
        }
    }
}
Also used : VcsRefType(com.intellij.vcs.log.VcsRefType) VcsRef(com.intellij.vcs.log.VcsRef) MultiMap(com.intellij.util.containers.MultiMap) RefGroup(com.intellij.vcs.log.RefGroup)

Example 58 with MultiMap

use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.

the class VcsLogRepoSizeCollector method groupRootsByVcs.

@NotNull
private static MultiMap<VcsKey, VirtualFile> groupRootsByVcs(@NotNull 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;
}
Also used : VcsKey(com.intellij.openapi.vcs.VcsKey) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsLogProvider(com.intellij.vcs.log.VcsLogProvider) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap) NotNull(org.jetbrains.annotations.NotNull)

Example 59 with MultiMap

use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.

the class CloudGitChooseAccountStepImpl method updateDataModel.

@Override
public void updateDataModel() {
    super.updateDataModel();
    final MultiMap<CloudGitProjectRoot, DetectedSourceRoot> project2sourceRoots = new MultiMap<>();
    new RootIterator() {

        CloudGitProjectRoot lastProjectRoot = null;

        @Override
        protected void processProjectRoot(CloudGitProjectRoot root) {
            lastProjectRoot = root;
            project2sourceRoots.put(lastProjectRoot, new ArrayList<>());
        }

        @Override
        protected void processJavaSourceRoot(DetectedSourceRoot root) {
            project2sourceRoots.putValue(lastProjectRoot, root);
        }
    }.iterate();
    List<ModuleDescriptor> modules = new ArrayList<>(myProjectDescriptor.getModules());
    for (Map.Entry<CloudGitProjectRoot, Collection<DetectedSourceRoot>> project2sourceRootsEntry : project2sourceRoots.entrySet()) {
        final CloudGitProjectRoot projectRoot = project2sourceRootsEntry.getKey();
        final File directory = projectRoot.getDirectory();
        ModuleDescriptor moduleDescriptor = new ModuleDescriptor(directory, StdModuleTypes.JAVA, project2sourceRootsEntry.getValue());
        final String applicationName = projectRoot.getApplicationName();
        moduleDescriptor.addConfigurationUpdater(new ModuleBuilder.ModuleConfigurationUpdater() {

            @Override
            public void update(@NotNull final Module module, @NotNull ModifiableRootModel rootModel) {
                final MessageBusConnection connection = module.getProject().getMessageBus().connect();
                connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {

                    @Override
                    public void moduleAdded(@NotNull Project project, @NotNull Module addedModule) {
                        if (addedModule == module) {
                            StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> onModuleAdded(module));
                            connection.disconnect();
                        }
                    }
                });
            }

            private void onModuleAdded(Module module) {
                createRunConfiguration(module, applicationName);
                GitInit.refreshAndConfigureVcsMappings(module.getProject(), projectRoot.getRepositoryRoot(), directory.getAbsolutePath());
            }
        });
        modules.add(moduleDescriptor);
    }
    myProjectDescriptor.setModules(modules);
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModuleListener(com.intellij.openapi.project.ModuleListener) ModuleBuilder(com.intellij.ide.util.projectWizard.ModuleBuilder) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull) DetectedSourceRoot(com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) MultiMap(com.intellij.util.containers.MultiMap) ModuleDescriptor(com.intellij.ide.util.importProject.ModuleDescriptor) Project(com.intellij.openapi.project.Project) Collection(java.util.Collection) Module(com.intellij.openapi.module.Module) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap) File(java.io.File)

Example 60 with MultiMap

use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.

the class GitRefManager method groupForTable.

@NotNull
@Override
public List<RefGroup> groupForTable(@NotNull Collection<VcsRef> references, boolean compact, boolean showTagNames) {
    List<VcsRef> sortedReferences = ContainerUtil.sorted(references, myLabelsComparator);
    MultiMap<VcsRefType, VcsRef> groupedRefs = ContainerUtil.groupBy(sortedReferences, VcsRef::getType);
    List<RefGroup> result = ContainerUtil.newArrayList();
    if (groupedRefs.isEmpty())
        return result;
    VcsRef head = null;
    Map.Entry<VcsRefType, Collection<VcsRef>> firstGroup = ObjectUtils.notNull(ContainerUtil.getFirstItem(groupedRefs.entrySet()));
    if (firstGroup.getKey().equals(HEAD)) {
        head = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(firstGroup.getValue()));
        groupedRefs.remove(HEAD, head);
    }
    GitRepository repository = getRepository(references);
    if (repository != null) {
        result.addAll(getTrackedRefs(groupedRefs, repository));
    }
    result.forEach(refGroup -> {
        groupedRefs.remove(LOCAL_BRANCH, refGroup.getRefs().get(0));
        groupedRefs.remove(REMOTE_BRANCH, refGroup.getRefs().get(1));
    });
    SimpleRefGroup.buildGroups(groupedRefs, compact, showTagNames, result);
    if (head != null) {
        if (repository != null && !repository.isOnBranch()) {
            result.add(0, new SimpleRefGroup("!", Collections.singletonList(head)));
        } else {
            if (!result.isEmpty()) {
                RefGroup first = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(result));
                first.getRefs().add(0, head);
            } else {
                result.add(0, new SimpleRefGroup("", Collections.singletonList(head)));
            }
        }
    }
    return result;
}
Also used : GitRepository(git4idea.repo.GitRepository) SimpleRefGroup(com.intellij.vcs.log.impl.SimpleRefGroup) MultiMap(com.intellij.util.containers.MultiMap) SimpleRefGroup(com.intellij.vcs.log.impl.SimpleRefGroup) SingletonRefGroup(com.intellij.vcs.log.impl.SingletonRefGroup) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MultiMap (com.intellij.util.containers.MultiMap)138 NotNull (org.jetbrains.annotations.NotNull)37 UsageInfo (com.intellij.usageView.UsageInfo)26 VirtualFile (com.intellij.openapi.vfs.VirtualFile)25 Project (com.intellij.openapi.project.Project)18 PsiElement (com.intellij.psi.PsiElement)18 ConflictsDialog (com.intellij.refactoring.ui.ConflictsDialog)16 Collection (java.util.Collection)16 Nullable (org.jetbrains.annotations.Nullable)15 Map (java.util.Map)14 File (java.io.File)11 HashSet (com.intellij.util.containers.HashSet)10 ContainerUtil (com.intellij.util.containers.ContainerUtil)9 THashSet (gnu.trove.THashSet)9 java.util (java.util)9 Module (com.intellij.openapi.module.Module)8 com.intellij.psi (com.intellij.psi)8 Pair (com.intellij.openapi.util.Pair)7 PsiFile (com.intellij.psi.PsiFile)7 ArrayList (java.util.ArrayList)7