Search in sources :

Example 96 with MultiMap

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

the class NestingTreeStructureProvider method getNestingRules.

@NotNull
private Collection<NestingRule> getNestingRules() {
    if (myNestingRules == null) {
        myNestingRules = new THashSet<>();
        final MultiMap<String, String> childToParentSuffix = new MultiMap<>();
        final MultiMap<String, String> parentToChildSuffix = new MultiMap<>();
        final ProjectViewNestingRulesProvider.Consumer consumer = new ProjectViewNestingRulesProvider.Consumer() {

            @Override
            public void addNestingRule(@NotNull final String parentFileSuffix, @NotNull final String childFileSuffix) {
                LOG.assertTrue(!parentFileSuffix.isEmpty() && !childFileSuffix.isEmpty(), "file suffix must not be empty");
                LOG.assertTrue(!parentFileSuffix.equals(childFileSuffix), "parent and child suffixes must be different: " + parentFileSuffix);
                myNestingRules.add(new NestingRule(parentFileSuffix, childFileSuffix));
                childToParentSuffix.putValue(childFileSuffix, parentFileSuffix);
                parentToChildSuffix.putValue(parentFileSuffix, childFileSuffix);
                // for all cases like A -> B -> C we also add a rule A -> C
                for (String s : parentToChildSuffix.get(childFileSuffix)) {
                    myNestingRules.add(new NestingRule(parentFileSuffix, s));
                    parentToChildSuffix.putValue(parentFileSuffix, s);
                    childToParentSuffix.putValue(s, parentFileSuffix);
                }
                for (String s : childToParentSuffix.get(parentFileSuffix)) {
                    myNestingRules.add(new NestingRule(s, childFileSuffix));
                    parentToChildSuffix.putValue(s, childFileSuffix);
                    childToParentSuffix.putValue(childFileSuffix, s);
                }
            }
        };
        for (ProjectViewNestingRulesProvider provider : EP_NAME.getExtensions()) {
            provider.addFileNestingRules(consumer);
        }
    }
    return myNestingRules;
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) NotNull(org.jetbrains.annotations.NotNull) ProjectViewNestingRulesProvider(com.intellij.ide.projectView.ProjectViewNestingRulesProvider) NotNull(org.jetbrains.annotations.NotNull)

Example 97 with MultiMap

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

the class UsageFavoriteNodeProvider method getFavoriteNodes.

@Override
public Collection<AbstractTreeNode> getFavoriteNodes(DataContext context, ViewSettings viewSettings) {
    final Project project = CommonDataKeys.PROJECT.getData(context);
    if (project == null) {
        return null;
    }
    final Usage[] usages = UsageView.USAGES_KEY.getData(context);
    if (usages != null) {
        final List<AbstractTreeNode> result = new SmartList<>();
        final MultiMap<VirtualFile, Usage> map = new MultiMap<>();
        final List<Usage> nonMapped = new ArrayList<>();
        for (Usage usage : usages) {
            if (usage instanceof UsageInFile) {
                map.putValue(((UsageInFile) usage).getFile(), usage);
            } else if (usage instanceof UsageInFiles) {
                final VirtualFile[] files = ((UsageInFiles) usage).getFiles();
                for (VirtualFile file : files) {
                    map.putValue(file, usage);
                }
            } else {
                nonMapped.add(usage);
            }
        }
        final TreeSet<VirtualFile> keys = new TreeSet<>(VIRTUAL_FILE_COMPARATOR);
        keys.addAll(map.keySet());
        for (VirtualFile key : keys) {
            final FileGroupingProjectNode grouping = new FileGroupingProjectNode(project, new File(key.getPath()), viewSettings);
            result.add(grouping);
            final Collection<Usage> subUsages = map.get(key);
            for (Usage usage : subUsages) {
                if (usage instanceof UsageInfo2UsageAdapter) {
                    final UsageProjectTreeNode node = new UsageProjectTreeNode(project, ((UsageInfo2UsageAdapter) usage).getUsageInfo(), viewSettings);
                    grouping.addChild(node);
                } else if (NullUsage.INSTANCE.equals(usage)) {
                    continue;
                } else {
                    grouping.addChild(new NoteProjectNode(project, new NoteNode(usage.getPresentation().getPlainText(), true), viewSettings));
                }
            }
        }
        for (Usage usage : nonMapped) {
            if (usage instanceof UsageInfo2UsageAdapter) {
                final UsageProjectTreeNode node = new UsageProjectTreeNode(project, ((UsageInfo2UsageAdapter) usage).getUsageInfo(), viewSettings);
                result.add(node);
            } else if (NullUsage.INSTANCE.equals(usage)) {
                continue;
            } else {
                result.add(new NoteProjectNode(project, new NoteNode(usage.getPresentation().getPlainText(), true), viewSettings));
            }
        }
        return result;
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NullUsage(com.intellij.usages.impl.NullUsage) Usage(com.intellij.usages.Usage) UsageInFiles(com.intellij.usages.rules.UsageInFiles) UsageInFile(com.intellij.usages.rules.UsageInFile) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Project(com.intellij.openapi.project.Project) MultiMap(com.intellij.util.containers.MultiMap) UsageInfo2UsageAdapter(com.intellij.usages.UsageInfo2UsageAdapter) SmartList(com.intellij.util.SmartList) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) UsageInFile(com.intellij.usages.rules.UsageInFile) File(java.io.File)

Example 98 with MultiMap

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

the class ApplyPatchDifferentiatedDialog method runExecutor.

@CalledInAwt
private void runExecutor(ApplyPatchExecutor executor) {
    final Collection<AbstractFilePatchInProgress> included = getIncluded();
    if (included.isEmpty())
        return;
    final MultiMap<VirtualFile, AbstractFilePatchInProgress> patchGroups = new MultiMap<>();
    for (AbstractFilePatchInProgress patchInProgress : included) {
        patchGroups.putValue(patchInProgress.getBase(), patchInProgress);
    }
    final LocalChangeList selected = getSelectedChangeList();
    FilePresentationModel presentation = myRecentPathFileChange.get();
    VirtualFile vf = presentation != null ? presentation.getVf() : null;
    executor.apply(getOriginalRemaining(), patchGroups, selected, vf == null ? null : vf.getName(), myReader == null ? null : myReader.getAdditionalInfo(ApplyPatchDefaultExecutor.pathsFromGroups(patchGroups)));
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) LocalChangeList(com.intellij.openapi.vcs.changes.LocalChangeList) CalledInAwt(org.jetbrains.annotations.CalledInAwt)

Example 99 with MultiMap

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

the class ImportToShelfExecutor method apply.

@Override
public void apply(@NotNull List<FilePatch> remaining, @NotNull final MultiMap<VirtualFile, TextFilePatchInProgress> patchGroupsToApply, @Nullable LocalChangeList localList, @Nullable final String fileName, @Nullable ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) {
    if (fileName == null) {
        LOG.error("Patch file name shouldn't be null");
        return;
    }
    final VcsCatchingRunnable vcsCatchingRunnable = new VcsCatchingRunnable() {

        @Override
        public void runImpl() throws VcsException {
            final VirtualFile baseDir = myProject.getBaseDir();
            final File ioBase = new File(baseDir.getPath());
            final List<FilePatch> allPatches = new ArrayList<>();
            for (VirtualFile virtualFile : patchGroupsToApply.keySet()) {
                final File ioCurrentBase = new File(virtualFile.getPath());
                allPatches.addAll(ContainerUtil.map(patchGroupsToApply.get(virtualFile), new Function<TextFilePatchInProgress, TextFilePatch>() {

                    public TextFilePatch fun(TextFilePatchInProgress patchInProgress) {
                        final TextFilePatch was = patchInProgress.getPatch();
                        was.setBeforeName(PathUtil.toSystemIndependentName(FileUtil.getRelativePath(ioBase, new File(ioCurrentBase, was.getBeforeName()))));
                        was.setAfterName(PathUtil.toSystemIndependentName(FileUtil.getRelativePath(ioBase, new File(ioCurrentBase, was.getAfterName()))));
                        return was;
                    }
                }));
            }
            if (!allPatches.isEmpty()) {
                PatchEP[] patchTransitExtensions = null;
                if (additionalInfo != null) {
                    try {
                        final Map<String, PatchEP> extensions = new HashMap<>();
                        for (Map.Entry<String, Map<String, CharSequence>> entry : additionalInfo.compute().entrySet()) {
                            final String filePath = entry.getKey();
                            Map<String, CharSequence> extToValue = entry.getValue();
                            for (Map.Entry<String, CharSequence> innerEntry : extToValue.entrySet()) {
                                TransitExtension patchEP = (TransitExtension) extensions.get(innerEntry.getKey());
                                if (patchEP == null) {
                                    patchEP = new TransitExtension(innerEntry.getKey());
                                    extensions.put(innerEntry.getKey(), patchEP);
                                }
                                patchEP.put(filePath, innerEntry.getValue());
                            }
                        }
                        Collection<PatchEP> values = extensions.values();
                        patchTransitExtensions = values.toArray(new PatchEP[values.size()]);
                    } catch (PatchSyntaxException e) {
                        VcsBalloonProblemNotifier.showOverChangesView(myProject, "Can not import additional patch info: " + e.getMessage(), MessageType.ERROR);
                    }
                }
                try {
                    final ShelvedChangeList shelvedChangeList = ShelveChangesManager.getInstance(myProject).importFilePatches(fileName, allPatches, patchTransitExtensions);
                    ShelvedChangesViewManager.getInstance(myProject).activateView(shelvedChangeList);
                } catch (IOException e) {
                    throw new VcsException(e);
                }
            }
        }
    };
    ProgressManager.getInstance().runProcessWithProgressSynchronously(vcsCatchingRunnable, "Import Patch to Shelf", true, myProject);
    if (!vcsCatchingRunnable.get().isEmpty()) {
        AbstractVcsHelper.getInstance(myProject).showErrors(vcsCatchingRunnable.get(), IMPORT_TO_SHELF);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ShelvedChangeList(com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList) Function(com.intellij.util.Function) PatchEP(com.intellij.openapi.diff.impl.patch.PatchEP) VcsCatchingRunnable(com.intellij.vcsUtil.VcsCatchingRunnable) IOException(java.io.IOException) TextFilePatch(com.intellij.openapi.diff.impl.patch.TextFilePatch) FilePatch(com.intellij.openapi.diff.impl.patch.FilePatch) PatchSyntaxException(com.intellij.openapi.diff.impl.patch.PatchSyntaxException) TextFilePatch(com.intellij.openapi.diff.impl.patch.TextFilePatch) VcsException(com.intellij.openapi.vcs.VcsException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) MultiMap(com.intellij.util.containers.MultiMap)

Example 100 with MultiMap

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

the class ConvertInterfaceToClassIntention method processIntention.

@Override
protected void processIntention(@NotNull PsiElement element) throws IncorrectOperationException {
    final PsiClass anInterface = (PsiClass) element.getParent();
    final SearchScope searchScope = anInterface.getUseScope();
    final Collection<PsiClass> inheritors = ClassInheritorsSearch.search(anInterface, searchScope, false).findAll();
    final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    inheritors.forEach(aClass -> {
        final PsiReferenceList extendsList = aClass.getExtendsList();
        if (extendsList == null) {
            return;
        }
        final PsiJavaCodeReferenceElement[] referenceElements = extendsList.getReferenceElements();
        if (referenceElements.length > 0) {
            final PsiElement target = referenceElements[0].resolve();
            if (target instanceof PsiClass && !CommonClassNames.JAVA_LANG_OBJECT.equals(((PsiClass) target).getQualifiedName())) {
                conflicts.putValue(aClass, IntentionPowerPackBundle.message("0.already.extends.1.and.will.not.compile.after.converting.2.to.a.class", RefactoringUIUtil.getDescription(aClass, true), RefactoringUIUtil.getDescription(target, true), RefactoringUIUtil.getDescription(anInterface, false)));
            }
        }
    });
    final PsiFunctionalExpression functionalExpression = FunctionalExpressionSearch.search(anInterface, searchScope).findFirst();
    if (functionalExpression != null) {
        final String conflictMessage = ClassPresentationUtil.getFunctionalExpressionPresentation(functionalExpression, true) + " will not compile after converting " + RefactoringUIUtil.getDescription(anInterface, false) + " to a class";
        conflicts.putValue(functionalExpression, conflictMessage);
    }
    final boolean conflictsDialogOK;
    if (conflicts.isEmpty()) {
        conflictsDialogOK = true;
    } else {
        final Application application = ApplicationManager.getApplication();
        if (application.isUnitTestMode()) {
            throw new BaseRefactoringProcessor.ConflictsInTestsException(conflicts.values());
        }
        final ConflictsDialog conflictsDialog = new ConflictsDialog(anInterface.getProject(), conflicts, () -> convertInterfaceToClass(anInterface, inheritors));
        conflictsDialogOK = conflictsDialog.showAndGet();
    }
    if (conflictsDialogOK) {
        convertInterfaceToClass(anInterface, inheritors);
    }
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) SearchScope(com.intellij.psi.search.SearchScope) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) Application(com.intellij.openapi.application.Application)

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