Search in sources :

Example 71 with MultiMap

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

the class ChooseResourceDialog method initializeThemeAttributes.

private static MultiMap<ResourceType, String> initializeThemeAttributes(@NotNull Configuration configuration, @NotNull ResourceResolver resolver) {
    MultiMap<ResourceType, String> attrs = new MultiMap<>();
    String themeName = configuration.getTheme();
    assert themeName != null;
    for (ItemResourceValue item : ResolutionUtils.getThemeAttributes(resolver, themeName)) {
        ResourceType type = ResolutionUtils.getAttrType(item, configuration);
        if (type != null) {
            attrs.putValue(type, ResolutionUtils.getQualifiedItemName(item));
        }
    }
    return attrs;
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) ResourceType(com.android.resources.ResourceType)

Example 72 with MultiMap

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

the class FlexMoveClassProcessor method detectConflicts.

private MultiMap<PsiElement, String> detectConflicts(UsageInfo[] usages) {
    MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    final Collection<PsiElement> filesToMove = Arrays.asList(myElementsToMove);
    JSVisibilityUtil.Options options = new JSVisibilityUtil.Options();
    for (PsiElement file : filesToMove) {
        options.overridePackage(file, myTargetPackage);
    }
    for (UsageInfo usage : usages) {
        final PsiElement element = usage.getElement();
        if (!(element instanceof JSReferenceExpression)) {
            continue;
        }
        if (CommonRefactoringUtil.isAncestor(element, filesToMove)) {
            continue;
        }
        JSReferenceExpression refExpr = (JSReferenceExpression) element;
        final PsiElement resolved = refExpr.resolve();
        if (!(resolved instanceof JSQualifiedNamedElement)) {
            continue;
        }
        PsiElement containingClass = null;
        if (resolved instanceof JSFunction && ((JSFunction) resolved).isConstructor() && myElements.contains(containingClass = resolved.getParent()) || myElements.contains(resolved)) {
            JSRefactoringConflictsUtil.checkAccessibility((JSAttributeListOwner) resolved, (JSClass) containingClass, null, refExpr, conflicts, true, options);
        }
    }
    for (PsiElement fileToMove : filesToMove) {
        JSRefactoringConflictsUtil.checkOutgoingReferencesAccessibility(fileToMove, filesToMove, null, true, conflicts, Conditions.alwaysTrue(), options);
    }
    //JSRefactoringConflictsUtil.analyzeModuleConflicts(myProject, myElements, usages, myTargetDirectory, conflicts);
    return conflicts;
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) JSVisibilityUtil(com.intellij.lang.javascript.refactoring.JSVisibilityUtil) PsiElement(com.intellij.psi.PsiElement)

Example 73 with MultiMap

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

the class VcsDirtyScopeImpl method addDirtyData.

public void addDirtyData(@NotNull Collection<FilePath> dirs, @NotNull Collection<FilePath> files) {
    final HashSet<FilePath> newFiles = new HashSet<>(files);
    // if the same dir is added recursively and not recursively, prefer recursive mark
    newFiles.removeAll(dirs);
    final MultiMap<VirtualFile, FileOrDir> perRoot = MultiMap.createSet();
    for (Map.Entry<VirtualFile, THashSet<FilePath>> entry : myDirtyDirectoriesRecursively.entrySet()) {
        // if the same dir is added recursively and not recursively, prefer recursive mark
        newFiles.removeAll(entry.getValue());
        for (FilePath path : entry.getValue()) {
            perRoot.putValue(entry.getKey(), new FileOrDir(path, true));
        }
    }
    for (Map.Entry<VirtualFile, THashSet<FilePath>> entry : myDirtyFiles.entrySet()) {
        for (FilePath path : entry.getValue()) {
            perRoot.putValue(entry.getKey(), new FileOrDir(path, false));
        }
    }
    for (FilePath dir : dirs) {
        addFilePathToMap(perRoot, dir, true);
    }
    for (FilePath file : newFiles) {
        addFilePathToMap(perRoot, file, false);
    }
    for (Map.Entry<VirtualFile, Collection<FileOrDir>> entry : perRoot.entrySet()) {
        final Collection<FileOrDir> set = entry.getValue();
        final Collection<FileOrDir> newCollection = FileUtil.removeAncestors(set, new Convertor<FileOrDir, String>() {

            @Override
            public String convert(FileOrDir o) {
                return o.myPath.getPath();
            }
        }, new PairProcessor<FileOrDir, FileOrDir>() {

            @Override
            public boolean process(FileOrDir parent, FileOrDir child) {
                if (parent.myRecursive) {
                    return true;
                }
                // if under non-recursive dirty dir, generally do not remove child with one exception...
                if (child.myRecursive || child.myPath.isDirectory()) {
                    return false;
                }
                // only if dir non-recursively + non-recursive file child -> can be truncated to dir only
                return Comparing.equal(child.myPath.getParentPath(), parent.myPath);
            }
        });
        set.retainAll(newCollection);
    }
    myAffectedContentRoots.addAll(perRoot.keySet());
    for (Map.Entry<VirtualFile, Collection<FileOrDir>> entry : perRoot.entrySet()) {
        final VirtualFile root = entry.getKey();
        final THashSet<FilePath> curFiles = newFilePathsSet();
        final THashSet<FilePath> curDirs = newFilePathsSet();
        final Collection<FileOrDir> value = entry.getValue();
        for (FileOrDir fileOrDir : value) {
            if (fileOrDir.myRecursive) {
                curDirs.add(fileOrDir.myPath);
            } else {
                curFiles.add(fileOrDir.myPath);
            }
        }
        // also, we replace contents, so here's no merging
        if (!curDirs.isEmpty()) {
            myDirtyDirectoriesRecursively.put(root, curDirs);
        }
        if (!curFiles.isEmpty()) {
            myDirtyFiles.put(root, curFiles);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashSet(gnu.trove.THashSet) MultiMap(com.intellij.util.containers.MultiMap) THashSet(gnu.trove.THashSet)

Example 74 with MultiMap

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

the class AttachToLocalProcessAction method collectAttachItems.

@NotNull
public static List<AttachItem> collectAttachItems(@NotNull final Project project, @NotNull ProcessInfo[] processList, @NotNull ProgressIndicator indicator, @NotNull XLocalAttachDebuggerProvider... providers) {
    MultiMap<XLocalAttachGroup, Pair<ProcessInfo, ArrayList<XLocalAttachDebugger>>> groupWithItems = new MultiMap<>();
    UserDataHolderBase dataHolder = new UserDataHolderBase();
    for (ProcessInfo eachInfo : processList) {
        MultiMap<XLocalAttachGroup, XLocalAttachDebugger> groupsWithDebuggers = new MultiMap<>();
        for (XLocalAttachDebuggerProvider eachProvider : providers) {
            indicator.checkCanceled();
            groupsWithDebuggers.putValues(eachProvider.getAttachGroup(), eachProvider.getAvailableDebuggers(project, eachInfo, dataHolder));
        }
        for (XLocalAttachGroup eachGroup : groupsWithDebuggers.keySet()) {
            Collection<XLocalAttachDebugger> debuggers = groupsWithDebuggers.get(eachGroup);
            if (!debuggers.isEmpty()) {
                groupWithItems.putValue(eachGroup, Pair.create(eachInfo, new ArrayList<>(debuggers)));
            }
        }
    }
    ArrayList<XLocalAttachGroup> sortedGroups = new ArrayList<>(groupWithItems.keySet());
    sortedGroups.sort(Comparator.comparingInt(XLocalAttachGroup::getOrder));
    List<AttachItem> currentItems = new ArrayList<>();
    for (final XLocalAttachGroup eachGroup : sortedGroups) {
        List<Pair<ProcessInfo, ArrayList<XLocalAttachDebugger>>> sortedItems = new ArrayList<>(groupWithItems.get(eachGroup));
        sortedItems.sort((a, b) -> eachGroup.compare(project, a.first, b.first, dataHolder));
        boolean first = true;
        for (Pair<ProcessInfo, ArrayList<XLocalAttachDebugger>> eachItem : sortedItems) {
            currentItems.add(new AttachItem(eachGroup, first, eachItem.first, eachItem.second, dataHolder));
            first = false;
        }
    }
    List<AttachItem> currentHistoryItems = new ArrayList<>();
    List<HistoryItem> history = getHistory(project);
    for (int i = history.size() - 1; i >= 0; i--) {
        HistoryItem eachHistoryItem = history.get(i);
        for (AttachItem eachCurrentItem : currentItems) {
            boolean isSuitableItem = eachHistoryItem.getGroup().equals(eachCurrentItem.getGroup()) && eachHistoryItem.getProcessInfo().getCommandLine().equals(eachCurrentItem.getProcessInfo().getCommandLine());
            if (!isSuitableItem)
                continue;
            List<XLocalAttachDebugger> debuggers = eachCurrentItem.getDebuggers();
            int selectedDebugger = -1;
            for (int j = 0; j < debuggers.size(); j++) {
                XLocalAttachDebugger eachDebugger = debuggers.get(j);
                if (eachDebugger.getDebuggerDisplayName().equals(eachHistoryItem.getDebuggerName())) {
                    selectedDebugger = j;
                    break;
                }
            }
            if (selectedDebugger == -1)
                continue;
            currentHistoryItems.add(new AttachItem(eachCurrentItem.getGroup(), currentHistoryItems.isEmpty(), XDebuggerBundle.message("xdebugger.attach.toLocal.popup.recent"), eachCurrentItem.getProcessInfo(), debuggers, selectedDebugger, dataHolder));
        }
    }
    currentHistoryItems.addAll(currentItems);
    return currentHistoryItems;
}
Also used : UserDataHolderBase(com.intellij.openapi.util.UserDataHolderBase) ProcessInfo(com.intellij.execution.process.ProcessInfo) XLocalAttachDebugger(com.intellij.xdebugger.attach.XLocalAttachDebugger) MultiMap(com.intellij.util.containers.MultiMap) XLocalAttachGroup(com.intellij.xdebugger.attach.XLocalAttachGroup) XLocalAttachDebuggerProvider(com.intellij.xdebugger.attach.XLocalAttachDebuggerProvider) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 75 with MultiMap

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

the class ProjectLoadingErrorsNotifierImpl method fireNotifications.

private void fireNotifications() {
    final MultiMap<ConfigurationErrorType, ConfigurationErrorDescription> descriptionsMap = new MultiMap<>();
    synchronized (myLock) {
        if (myErrors.isEmpty())
            return;
        descriptionsMap.putAllValues(myErrors);
        myErrors.clear();
    }
    for (final ConfigurationErrorType type : descriptionsMap.keySet()) {
        final Collection<ConfigurationErrorDescription> descriptions = descriptionsMap.get(type);
        if (descriptions.isEmpty())
            continue;
        final String invalidElements = getInvalidElementsString(type, descriptions);
        final String errorText = ProjectBundle.message("error.message.configuration.cannot.load") + " " + invalidElements + " <a href=\"\">Details...</a>";
        Notifications.Bus.notify(new Notification("Project Loading Error", "Error Loading Project", errorText, NotificationType.ERROR, new NotificationListener() {

            @Override
            public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
                final List<ConfigurationErrorDescription> validDescriptions = ContainerUtil.findAll(descriptions, errorDescription -> errorDescription.isValid());
                if (RemoveInvalidElementsDialog.showDialog(myProject, CommonBundle.getErrorTitle(), type, invalidElements, validDescriptions)) {
                    notification.expire();
                }
            }
        }), myProject);
    }
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) HyperlinkEvent(javax.swing.event.HyperlinkEvent) ConfigurationErrorDescription(com.intellij.openapi.module.ConfigurationErrorDescription) ConfigurationErrorType(com.intellij.openapi.module.ConfigurationErrorType) NotNull(org.jetbrains.annotations.NotNull) Notification(com.intellij.notification.Notification) NotificationListener(com.intellij.notification.NotificationListener)

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