Search in sources :

Example 51 with MultiMap

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

the class AbstractDependencyDataService method importData.

@Override
public void importData(@NotNull Collection<DataNode<E>> toImport, @Nullable ProjectData projectData, @NotNull Project project, @NotNull IdeModifiableModelsProvider modelsProvider) {
    if (toImport.isEmpty()) {
        return;
    }
    MultiMap<DataNode<ModuleData>, DataNode<E>> byModule = ExternalSystemApiUtil.groupBy(toImport, ModuleData.class);
    for (Map.Entry<DataNode<ModuleData>, Collection<DataNode<E>>> entry : byModule.entrySet()) {
        final DataNode<ModuleData> moduleDataNode = entry.getKey();
        Module module = modelsProvider.findIdeModule(moduleDataNode.getData());
        if (module == null) {
            LOG.warn(String.format("Can't import dependencies %s. Reason: target module (%s) is not found at the ide and can't be imported", entry.getValue(), moduleDataNode));
            continue;
        }
        final Map<OrderEntry, OrderAware> moduleDependenciesOrder = importData(entry.getValue(), module, modelsProvider);
        final Map<OrderEntry, OrderAware> orderEntryDataMap = moduleDataNode.getUserData(AbstractModuleDataService.ORDERED_DATA_MAP_KEY);
        if (orderEntryDataMap != null) {
            orderEntryDataMap.putAll(moduleDependenciesOrder);
        } else {
            moduleDataNode.putUserData(AbstractModuleDataService.ORDERED_DATA_MAP_KEY, moduleDependenciesOrder);
        }
    }
}
Also used : DataNode(com.intellij.openapi.externalSystem.model.DataNode) Module(com.intellij.openapi.module.Module) MultiMap(com.intellij.util.containers.MultiMap)

Example 52 with MultiMap

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

the class ContentRootDataService method importData.

@Override
public void importData(@NotNull Collection<DataNode<ContentRootData>> toImport, @Nullable ProjectData projectData, @NotNull Project project, @NotNull IdeModifiableModelsProvider modelsProvider) {
    if (toImport.isEmpty()) {
        return;
    }
    boolean isNewlyImportedProject = project.getUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT) == Boolean.TRUE;
    boolean forceDirectoriesCreation = false;
    DataNode<ProjectData> projectDataNode = ExternalSystemApiUtil.findParent(toImport.iterator().next(), ProjectKeys.PROJECT);
    if (projectDataNode != null) {
        forceDirectoriesCreation = projectDataNode.getUserData(CREATE_EMPTY_DIRECTORIES) == Boolean.TRUE;
    }
    Set<Module> modulesToExpand = ContainerUtil.newTroveSet();
    MultiMap<DataNode<ModuleData>, DataNode<ContentRootData>> byModule = ExternalSystemApiUtil.groupBy(toImport, ModuleData.class);
    for (Map.Entry<DataNode<ModuleData>, Collection<DataNode<ContentRootData>>> entry : byModule.entrySet()) {
        Module module = entry.getKey().getUserData(AbstractModuleDataService.MODULE_KEY);
        module = module != null ? module : modelsProvider.findIdeModule(entry.getKey().getData());
        if (module == null) {
            LOG.warn(String.format("Can't import content roots. Reason: target module (%s) is not found at the ide. Content roots: %s", entry.getKey(), entry.getValue()));
            continue;
        }
        importData(modelsProvider, entry.getValue(), module, forceDirectoriesCreation);
        if (forceDirectoriesCreation || (isNewlyImportedProject && projectData != null && projectData.getLinkedExternalProjectPath().equals(ExternalSystemApiUtil.getExternalProjectPath(module)))) {
            modulesToExpand.add(module);
        }
    }
    if (!modulesToExpand.isEmpty()) {
        for (Module module : modulesToExpand) {
            String productionModuleName = modelsProvider.getProductionModuleName(module);
            if (productionModuleName == null || !modulesToExpand.contains(modelsProvider.findIdeModule(productionModuleName))) {
                VirtualFile[] roots = modelsProvider.getModifiableRootModel(module).getContentRoots();
                if (roots.length > 0) {
                    VirtualFile virtualFile = roots[0];
                    ExternalSystemUtil.invokeLater(project, ModalityState.NON_MODAL, () -> {
                        final ProjectView projectView = ProjectView.getInstance(project);
                        projectView.changeViewCB(ProjectViewPane.ID, null).doWhenProcessed(() -> projectView.selectCB(null, virtualFile, false));
                    });
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentRootData(com.intellij.openapi.externalSystem.model.project.ContentRootData) Collection(java.util.Collection) ProjectView(com.intellij.ide.projectView.ProjectView) Module(com.intellij.openapi.module.Module) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 53 with MultiMap

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

the class ContentRootPanel method addFolderGroupComponents.

protected void addFolderGroupComponents() {
    final SourceFolder[] sourceFolders = getContentEntry().getSourceFolders();
    MultiMap<JpsModuleSourceRootType<?>, SourceFolder> folderByType = new MultiMap<>();
    for (SourceFolder folder : sourceFolders) {
        if (!folder.isSynthetic()) {
            folderByType.putValue(folder.getRootType(), folder);
        }
    }
    Insets insets = JBUI.insetsBottom(10);
    GridBagConstraints constraints = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, insets, 0, 0);
    for (ModuleSourceRootEditHandler<?> editor : myModuleSourceRootEditHandlers) {
        Collection<SourceFolder> folders = folderByType.get(editor.getRootType());
        if (folders.isEmpty())
            continue;
        ContentFolder[] foldersArray = folders.toArray(new ContentFolder[folders.size()]);
        final JComponent sourcesComponent = createFolderGroupComponent(editor.getRootsGroupTitle(), foldersArray, editor.getRootsGroupColor(), editor);
        add(sourcesComponent, constraints);
    }
    ExcludeFolder[] excluded = getContentEntry().getExcludeFolders();
    if (excluded.length > 0) {
        final JComponent excludedComponent = createFolderGroupComponent(ProjectBundle.message("module.paths.excluded.group"), excluded, EXCLUDED_COLOR, null);
        this.add(excludedComponent, constraints);
    }
}
Also used : SourceFolder(com.intellij.openapi.roots.SourceFolder) MultiMap(com.intellij.util.containers.MultiMap) JpsModuleSourceRootType(org.jetbrains.jps.model.module.JpsModuleSourceRootType) ContentFolder(com.intellij.openapi.roots.ContentFolder) ExcludeFolder(com.intellij.openapi.roots.ExcludeFolder)

Example 54 with MultiMap

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

the class GenericInlineHandler method invoke.

public static boolean invoke(final PsiElement element, @Nullable Editor editor, final InlineHandler languageSpecific) {
    final PsiReference invocationReference = editor != null ? TargetElementUtil.findReference(editor) : null;
    final InlineHandler.Settings settings = languageSpecific.prepareInlineElement(element, editor, invocationReference != null);
    if (settings == null || settings == InlineHandler.Settings.CANNOT_INLINE_SETTINGS) {
        return settings != null;
    }
    final Collection<? extends PsiReference> allReferences;
    if (settings.isOnlyOneReferenceToInline()) {
        allReferences = Collections.singleton(invocationReference);
    } else {
        final Ref<Collection<? extends PsiReference>> usagesRef = new Ref<>();
        ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> usagesRef.set(ReferencesSearch.search(element).findAll()), "Find Usages", false, element.getProject());
        allReferences = usagesRef.get();
    }
    final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    final Map<Language, InlineHandler.Inliner> inliners = initializeInliners(element, settings, allReferences);
    for (PsiReference reference : allReferences) {
        collectConflicts(reference, element, inliners, conflicts);
    }
    final Project project = element.getProject();
    if (!conflicts.isEmpty()) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            throw new BaseRefactoringProcessor.ConflictsInTestsException(conflicts.values());
        } else {
            final ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts);
            if (!conflictsDialog.showAndGet()) {
                return true;
            }
        }
    }
    HashSet<PsiElement> elements = new HashSet<>();
    for (PsiReference reference : allReferences) {
        PsiElement refElement = reference.getElement();
        if (refElement != null) {
            elements.add(refElement);
        }
    }
    if (!settings.isOnlyOneReferenceToInline()) {
        elements.add(element);
    }
    if (!CommonRefactoringUtil.checkReadOnlyStatusRecursively(project, elements, true)) {
        return true;
    }
    ApplicationManager.getApplication().runWriteAction(() -> {
        final String subj = element instanceof PsiNamedElement ? ((PsiNamedElement) element).getName() : "element";
        CommandProcessor.getInstance().executeCommand(project, () -> {
            final PsiReference[] references = sortDepthFirstRightLeftOrder(allReferences);
            final UsageInfo[] usages = new UsageInfo[references.length];
            for (int i = 0; i < references.length; i++) {
                usages[i] = new UsageInfo(references[i]);
            }
            for (UsageInfo usage : usages) {
                inlineReference(usage, element, inliners);
            }
            if (!settings.isOnlyOneReferenceToInline()) {
                languageSpecific.removeDefinition(element, settings);
            }
        }, RefactoringBundle.message("inline.command", StringUtil.notNullize(subj, "<nameless>")), null);
    });
    return true;
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement) PsiReference(com.intellij.psi.PsiReference) MultiMap(com.intellij.util.containers.MultiMap) Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) Language(com.intellij.lang.Language) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) InlineHandler(com.intellij.lang.refactoring.InlineHandler) PsiElement(com.intellij.psi.PsiElement) UsageInfo(com.intellij.usageView.UsageInfo) HashSet(com.intellij.util.containers.HashSet)

Example 55 with MultiMap

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

the class ToolWindowTaskService method processData.

@Override
protected void processData(@NotNull Collection<DataNode<TaskData>> nodes, @NotNull Project project) {
    if (nodes.isEmpty()) {
        return;
    }
    ProjectSystemId externalSystemId = nodes.iterator().next().getData().getOwner();
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
    assert manager != null;
    ExternalSystemKeymapExtension.updateActions(project, nodes);
    MultiMap<ExternalConfigPathAware, DataNode<TaskData>> grouped = ContainerUtil.groupBy(nodes, TASK_HOLDER_RETRIEVAL_STRATEGY);
    Map<String, Collection<ExternalTaskPojo>> data = ContainerUtilRt.newHashMap();
    for (Map.Entry<ExternalConfigPathAware, Collection<DataNode<TaskData>>> entry : grouped.entrySet()) {
        data.put(entry.getKey().getLinkedExternalProjectPath(), ContainerUtilRt.map2List(entry.getValue(), MAPPER));
    }
    AbstractExternalSystemLocalSettings settings = manager.getLocalSettingsProvider().fun(project);
    Map<String, Collection<ExternalTaskPojo>> availableTasks = ContainerUtilRt.newHashMap(settings.getAvailableTasks());
    availableTasks.putAll(data);
    settings.setAvailableTasks(availableTasks);
}
Also used : ExternalConfigPathAware(com.intellij.openapi.externalSystem.model.project.ExternalConfigPathAware) AbstractExternalSystemLocalSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings) DataNode(com.intellij.openapi.externalSystem.model.DataNode) Collection(java.util.Collection) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData)

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