Search in sources :

Example 1 with MultiValuesMap

use of com.intellij.openapi.util.MultiValuesMap in project intellij-community by JetBrains.

the class ArtifactBySourceFileFinderImpl method computeFileToArtifactsMap.

private MultiValuesMap<VirtualFile, Artifact> computeFileToArtifactsMap() {
    final MultiValuesMap<VirtualFile, Artifact> result = new MultiValuesMap<>();
    final ArtifactManager artifactManager = ArtifactManager.getInstance(myProject);
    for (final Artifact artifact : artifactManager.getArtifacts()) {
        final PackagingElementResolvingContext context = artifactManager.getResolvingContext();
        ArtifactUtil.processPackagingElements(artifact, null, new PackagingElementProcessor<PackagingElement<?>>() {

            @Override
            public boolean process(@NotNull PackagingElement<?> element, @NotNull PackagingElementPath path) {
                if (element instanceof FileOrDirectoryCopyPackagingElement<?>) {
                    final VirtualFile root = ((FileOrDirectoryCopyPackagingElement) element).findFile();
                    if (root != null) {
                        result.put(root, artifact);
                    }
                } else if (element instanceof ModuleOutputPackagingElement) {
                    for (VirtualFile sourceRoot : ((ModuleOutputPackagingElement) element).getSourceRoots(context)) {
                        result.put(sourceRoot, artifact);
                    }
                }
                return true;
            }
        }, context, true);
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MultiValuesMap(com.intellij.openapi.util.MultiValuesMap) PackagingElementResolvingContext(com.intellij.packaging.elements.PackagingElementResolvingContext) PackagingElement(com.intellij.packaging.elements.PackagingElement) FileOrDirectoryCopyPackagingElement(com.intellij.packaging.impl.elements.FileOrDirectoryCopyPackagingElement) ModuleOutputPackagingElement(com.intellij.packaging.impl.elements.ModuleOutputPackagingElement) Artifact(com.intellij.packaging.artifacts.Artifact) ArtifactManager(com.intellij.packaging.artifacts.ArtifactManager) ModuleOutputPackagingElement(com.intellij.packaging.impl.elements.ModuleOutputPackagingElement)

Example 2 with MultiValuesMap

use of com.intellij.openapi.util.MultiValuesMap in project intellij-community by JetBrains.

the class FacetModelBase method getFacetsByType.

@Override
@NotNull
public <F extends Facet> Collection<F> getFacetsByType(FacetTypeId<F> typeId) {
    if (myType2Facets == null) {
        MultiValuesMap<FacetTypeId, Facet> typeToFacets = new MultiValuesMap<>();
        for (Facet facet : getAllFacets()) {
            typeToFacets.put(facet.getTypeId(), facet);
        }
        Map<FacetTypeId, Collection<Facet>> typeToFacetsCollection = new HashMap<>();
        for (FacetTypeId id : typeToFacets.keySet()) {
            final Collection<Facet> facets = typeToFacets.get(id);
            typeToFacetsCollection.put(id, Collections.unmodifiableCollection(facets));
        }
        myType2Facets = typeToFacetsCollection;
    }
    final Collection<F> facets = (Collection<F>) myType2Facets.get(typeId);
    return facets != null ? facets : Collections.<F>emptyList();
}
Also used : MultiValuesMap(com.intellij.openapi.util.MultiValuesMap) FacetTypeId(com.intellij.facet.FacetTypeId) Facet(com.intellij.facet.Facet) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with MultiValuesMap

use of com.intellij.openapi.util.MultiValuesMap in project intellij-community by JetBrains.

the class LogicalRootsManagerImpl method getRoots.

private synchronized Map<Module, MultiValuesMap<LogicalRootType, LogicalRoot>> getRoots(final ModuleManager moduleManager) {
    if (myRoots == null) {
        myRoots = new THashMap<>();
        final Module[] modules = moduleManager.getModules();
        for (Module module : modules) {
            final MultiValuesMap<LogicalRootType, LogicalRoot> map = new MultiValuesMap<>();
            for (Map.Entry<LogicalRootType, Collection<NotNullFunction>> entry : myProviders.entrySet()) {
                final Collection<NotNullFunction> functions = entry.getValue();
                for (NotNullFunction function : functions) {
                    map.putAll(entry.getKey(), (List<LogicalRoot>) function.fun(module));
                }
            }
            myRoots.put(module, map);
        }
    }
    return myRoots;
}
Also used : MultiValuesMap(com.intellij.openapi.util.MultiValuesMap) Module(com.intellij.openapi.module.Module) MultiValuesMap(com.intellij.openapi.util.MultiValuesMap) THashMap(gnu.trove.THashMap)

Example 4 with MultiValuesMap

use of com.intellij.openapi.util.MultiValuesMap in project intellij-community by JetBrains.

the class SameNamesJoiner method modify.

@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    if (parent instanceof JoinedNode)
        return children;
    ArrayList<AbstractTreeNode> result = new ArrayList<>();
    MultiValuesMap<Object, AbstractTreeNode> executed = new MultiValuesMap<>();
    for (Iterator<AbstractTreeNode> iterator = children.iterator(); iterator.hasNext(); ) {
        ProjectViewNode treeNode = (ProjectViewNode) iterator.next();
        Object o = treeNode.getValue();
        if (o instanceof PsiFile) {
            String name = ((PsiFile) o).getVirtualFile().getNameWithoutExtension();
            executed.put(name, treeNode);
        } else {
            executed.put(o, treeNode);
        }
    }
    Iterator<Object> keys = executed.keySet().iterator();
    while (keys.hasNext()) {
        Object each = keys.next();
        Collection<AbstractTreeNode> objects = executed.get(each);
        if (objects.size() > 1) {
            result.add(new JoinedNode(objects, new Joined(findPsiFileIn(objects))));
        } else if (objects.size() == 1) {
            result.add(objects.iterator().next());
        }
    }
    return result;
}
Also used : MultiValuesMap(com.intellij.openapi.util.MultiValuesMap) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with MultiValuesMap

use of com.intellij.openapi.util.MultiValuesMap in project intellij-community by JetBrains.

the class FacetModelBase method getFacetsByType.

@Override
@NotNull
public <F extends Facet> Collection<F> getFacetsByType(@NotNull Facet underlyingFacet, FacetTypeId<F> typeId) {
    if (myChildFacets == null) {
        MultiValuesMap<Pair<Facet, FacetTypeId>, Facet> children = new MultiValuesMap<>();
        for (Facet facet : getAllFacets()) {
            final Facet underlying = facet.getUnderlyingFacet();
            if (underlying != null) {
                children.put(Pair.create(underlying, facet.getTypeId()), facet);
            }
        }
        Map<Pair<Facet, FacetTypeId>, Collection<Facet>> childFacets = new HashMap<>();
        for (Pair<Facet, FacetTypeId> pair : children.keySet()) {
            final Collection<Facet> facets = children.get(pair);
            childFacets.put(pair, Collections.unmodifiableCollection(facets));
        }
        myChildFacets = childFacets;
    }
    //noinspection unchecked
    final Collection<F> facets = (Collection<F>) myChildFacets.get(new Pair(underlyingFacet, typeId));
    return facets != null ? facets : Collections.<F>emptyList();
}
Also used : MultiValuesMap(com.intellij.openapi.util.MultiValuesMap) FacetTypeId(com.intellij.facet.FacetTypeId) Pair(com.intellij.openapi.util.Pair) Facet(com.intellij.facet.Facet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MultiValuesMap (com.intellij.openapi.util.MultiValuesMap)6 NotNull (org.jetbrains.annotations.NotNull)3 Facet (com.intellij.facet.Facet)2 FacetTypeId (com.intellij.facet.FacetTypeId)2 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)2 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Module (com.intellij.openapi.module.Module)1 Pair (com.intellij.openapi.util.Pair)1 Artifact (com.intellij.packaging.artifacts.Artifact)1 ArtifactManager (com.intellij.packaging.artifacts.ArtifactManager)1 PackagingElement (com.intellij.packaging.elements.PackagingElement)1 PackagingElementResolvingContext (com.intellij.packaging.elements.PackagingElementResolvingContext)1 FileOrDirectoryCopyPackagingElement (com.intellij.packaging.impl.elements.FileOrDirectoryCopyPackagingElement)1 ModuleOutputPackagingElement (com.intellij.packaging.impl.elements.ModuleOutputPackagingElement)1 PsiFile (com.intellij.psi.PsiFile)1 THashMap (gnu.trove.THashMap)1 ArrayList (java.util.ArrayList)1