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;
}
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();
}
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;
}
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;
}
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();
}
Aggregations