Search in sources :

Example 41 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)

Example 42 with MultiMap

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

the class GradleProjectResolver method mergeModuleContentRoots.

private static void mergeModuleContentRoots(@NotNull Map<String, Counter> weightMap, @NotNull ExternalProject externalProject, @NotNull DataNode<? extends ModuleData> moduleNode) {
    final File buildDir = externalProject.getBuildDir();
    final MultiMap<String, ContentRootData> sourceSetRoots = MultiMap.create();
    Collection<DataNode<ContentRootData>> contentRootNodes = ExternalSystemApiUtil.findAll(moduleNode, ProjectKeys.CONTENT_ROOT);
    if (contentRootNodes.size() <= 1)
        return;
    for (DataNode<ContentRootData> contentRootNode : contentRootNodes) {
        File root = new File(contentRootNode.getData().getRootPath());
        if (FileUtil.isAncestor(buildDir, root, true))
            continue;
        while (weightMap.containsKey(root.getParent()) && weightMap.get(root.getParent()).count <= 1) {
            root = root.getParentFile();
        }
        ContentRootData mergedContentRoot = null;
        String rootPath = ExternalSystemApiUtil.toCanonicalPath(root.getAbsolutePath());
        Set<String> paths = ContainerUtil.newHashSet(sourceSetRoots.keySet());
        for (String path : paths) {
            if (FileUtil.isAncestor(rootPath, path, true)) {
                Collection<ContentRootData> values = sourceSetRoots.remove(path);
                if (values != null) {
                    sourceSetRoots.putValues(rootPath, values);
                }
            } else if (FileUtil.isAncestor(path, rootPath, false)) {
                Collection<ContentRootData> contentRoots = sourceSetRoots.get(path);
                for (ContentRootData rootData : contentRoots) {
                    if (StringUtil.equals(rootData.getRootPath(), path)) {
                        mergedContentRoot = rootData;
                        break;
                    }
                }
                if (mergedContentRoot == null) {
                    mergedContentRoot = contentRoots.iterator().next();
                }
                break;
            }
            if (sourceSetRoots.size() == 1)
                break;
        }
        if (mergedContentRoot == null) {
            mergedContentRoot = new ContentRootData(GradleConstants.SYSTEM_ID, root.getAbsolutePath());
            sourceSetRoots.putValue(mergedContentRoot.getRootPath(), mergedContentRoot);
        }
        for (ExternalSystemSourceType sourceType : ExternalSystemSourceType.values()) {
            for (ContentRootData.SourceRoot sourceRoot : contentRootNode.getData().getPaths(sourceType)) {
                mergedContentRoot.storePath(sourceType, sourceRoot.getPath(), sourceRoot.getPackagePrefix());
            }
        }
        contentRootNode.clear(true);
    }
    for (Map.Entry<String, Collection<ContentRootData>> entry : sourceSetRoots.entrySet()) {
        final String rootPath = entry.getKey();
        final ContentRootData ideContentRoot = new ContentRootData(GradleConstants.SYSTEM_ID, rootPath);
        for (ContentRootData rootData : entry.getValue()) {
            for (ExternalSystemSourceType sourceType : ExternalSystemSourceType.values()) {
                Collection<ContentRootData.SourceRoot> roots = rootData.getPaths(sourceType);
                for (ContentRootData.SourceRoot sourceRoot : roots) {
                    ideContentRoot.storePath(sourceType, sourceRoot.getPath(), sourceRoot.getPackagePrefix());
                }
            }
        }
        moduleNode.createChild(ProjectKeys.CONTENT_ROOT, ideContentRoot);
    }
}
Also used : DataNode(com.intellij.openapi.externalSystem.model.DataNode) File(java.io.File) MultiMap(com.intellij.util.containers.MultiMap)

Example 43 with MultiMap

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

the class JpsGroovycRunner method updateDependencies.

void updateDependencies(CompileContext context, List<File> toCompile, MultiMap<T, GroovycOutputParser.OutputItem> successfullyCompiled, final GroovyOutputConsumer outputConsumer, Builder builder) throws IOException {
    JavaBuilderUtil.registerFilesToCompile(context, toCompile);
    if (!successfullyCompiled.isEmpty()) {
        final Callbacks.Backend callback = JavaBuilderUtil.getDependenciesRegistrar(context);
        for (Map.Entry<T, Collection<GroovycOutputParser.OutputItem>> entry : successfullyCompiled.entrySet()) {
            final T target = entry.getKey();
            final Collection<GroovycOutputParser.OutputItem> compiled = entry.getValue();
            for (GroovycOutputParser.OutputItem item : compiled) {
                final String sourcePath = FileUtil.toSystemIndependentName(item.sourcePath);
                final String outputPath = FileUtil.toSystemIndependentName(item.outputPath);
                final File outputFile = new File(outputPath);
                final File srcFile = new File(sourcePath);
                try {
                    final byte[] bytes = FileUtil.loadFileBytes(outputFile);
                    if (Utils.IS_TEST_MODE || LOG.isDebugEnabled()) {
                        LOG.info("registerCompiledClass " + outputFile + " from " + srcFile);
                    }
                    outputConsumer.registerCompiledClass(target, srcFile, outputFile, bytes);
                    callback.associate(outputPath, sourcePath, new FailSafeClassReader(bytes));
                } catch (Throwable e) {
                    // need this to make sure that unexpected errors in, for example, ASM will not ruin the compilation
                    final String message = "Class dependency information may be incomplete! Error parsing generated class " + item.outputPath;
                    LOG.info(message, e);
                    context.processMessage(new CompilerMessage(builder.getPresentableName(), BuildMessage.Kind.WARNING, message + "\n" + CompilerMessage.getTextFromThrowable(e), sourcePath));
                }
                JavaBuilderUtil.registerSuccessfullyCompiled(context, srcFile);
            }
        }
    }
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) Callbacks(org.jetbrains.jps.builders.java.dependencyView.Callbacks) MultiMap(com.intellij.util.containers.MultiMap) File(java.io.File) FailSafeClassReader(com.intellij.compiler.instrumentation.FailSafeClassReader)

Example 44 with MultiMap

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

the class PsiSearchHelperImpl method distributePrimitives.

private static void distributePrimitives(@NotNull Map<SearchRequestCollector, Processor<PsiReference>> collectors, @NotNull Set<RequestWithProcessor> locals, @NotNull MultiMap<Set<IdIndexEntry>, RequestWithProcessor> globals, @NotNull List<Computable<Boolean>> customs, @NotNull Map<RequestWithProcessor, Processor<PsiElement>> localProcessors, @NotNull ProgressIndicator progress) {
    for (final Map.Entry<SearchRequestCollector, Processor<PsiReference>> entry : collectors.entrySet()) {
        final Processor<PsiReference> processor = entry.getValue();
        SearchRequestCollector collector = entry.getKey();
        for (final PsiSearchRequest primitive : collector.takeSearchRequests()) {
            final SearchScope scope = primitive.searchScope;
            if (scope instanceof LocalSearchScope) {
                registerRequest(locals, primitive, processor);
            } else {
                Set<IdIndexEntry> key = new HashSet<>(getWordEntries(primitive.word, primitive.caseSensitive));
                registerRequest(globals.getModifiable(key), primitive, processor);
            }
        }
        for (final Processor<Processor<PsiReference>> customAction : collector.takeCustomSearchActions()) {
            customs.add(() -> customAction.process(processor));
        }
    }
    for (Map.Entry<Set<IdIndexEntry>, Collection<RequestWithProcessor>> entry : globals.entrySet()) {
        for (RequestWithProcessor singleRequest : entry.getValue()) {
            PsiSearchRequest primitive = singleRequest.request;
            StringSearcher searcher = new StringSearcher(primitive.word, primitive.caseSensitive, true, false);
            BulkOccurrenceProcessor adapted = adaptProcessor(primitive, singleRequest.refProcessor);
            Processor<PsiElement> localProcessor = localProcessor(adapted, progress, searcher);
            assert !localProcessors.containsKey(singleRequest) || localProcessors.get(singleRequest) == localProcessor;
            localProcessors.put(singleRequest, localProcessor);
        }
    }
}
Also used : ReadActionProcessor(com.intellij.openapi.application.ReadActionProcessor) Processor(com.intellij.util.Processor) THashSet(gnu.trove.THashSet) IdIndexEntry(com.intellij.psi.impl.cache.impl.id.IdIndexEntry) THashMap(gnu.trove.THashMap) MultiMap(com.intellij.util.containers.MultiMap) THashSet(gnu.trove.THashSet) StringSearcher(com.intellij.util.text.StringSearcher)

Example 45 with MultiMap

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

the class PsiSearchHelperImpl method processRequests.

@Override
public boolean processRequests(@NotNull SearchRequestCollector collector, @NotNull Processor<PsiReference> processor) {
    final Map<SearchRequestCollector, Processor<PsiReference>> collectors = ContainerUtil.newHashMap();
    collectors.put(collector, processor);
    ProgressIndicator progress = getOrCreateIndicator();
    appendCollectorsFromQueryRequests(collectors);
    boolean result;
    do {
        MultiMap<Set<IdIndexEntry>, RequestWithProcessor> globals = new MultiMap<>();
        final List<Computable<Boolean>> customs = ContainerUtil.newArrayList();
        final Set<RequestWithProcessor> locals = ContainerUtil.newLinkedHashSet();
        Map<RequestWithProcessor, Processor<PsiElement>> localProcessors = new THashMap<>();
        distributePrimitives(collectors, locals, globals, customs, localProcessors, progress);
        result = processGlobalRequestsOptimized(globals, progress, localProcessors);
        if (result) {
            for (RequestWithProcessor local : locals) {
                result = processSingleRequest(local.request, local.refProcessor);
                if (!result)
                    break;
            }
            if (result) {
                for (Computable<Boolean> custom : customs) {
                    result = custom.compute();
                    if (!result)
                        break;
                }
            }
            if (!result)
                break;
        }
    } while (appendCollectorsFromQueryRequests(collectors));
    return result;
}
Also used : ReadActionProcessor(com.intellij.openapi.application.ReadActionProcessor) Processor(com.intellij.util.Processor) THashSet(gnu.trove.THashSet) MultiMap(com.intellij.util.containers.MultiMap) THashMap(gnu.trove.THashMap) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Aggregations

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