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