Search in sources :

Example 1 with MultiMap

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

the class SvnCheckinHandlerFactory method createVcsHandler.

@NotNull
@Override
protected CheckinHandler createVcsHandler(final CheckinProjectPanel panel) {
    final Project project = panel.getProject();
    final Collection<VirtualFile> commitRoots = panel.getRoots();
    return new CheckinHandler() {

        private Collection<Change> myChanges = panel.getSelectedChanges();

        @Override
        public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
            return null;
        }

        @Override
        public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer<Object, Object> additionalDataConsumer) {
            if (executor instanceof LocalCommitExecutor)
                return ReturnResult.COMMIT;
            final SvnVcs vcs = SvnVcs.getInstance(project);
            final MultiMap<String, WorkingCopyFormat> copiesInfo = splitIntoCopies(vcs, myChanges);
            final List<String> repoUrls = new ArrayList<>();
            for (Map.Entry<String, Collection<WorkingCopyFormat>> entry : copiesInfo.entrySet()) {
                if (entry.getValue().size() > 1) {
                    repoUrls.add(entry.getKey());
                }
            }
            if (!repoUrls.isEmpty()) {
                final String join = StringUtil.join(repoUrls, ",\n");
                final int isOk = Messages.showOkCancelDialog(project, SvnBundle.message("checkin.different.formats.involved", repoUrls.size() > 1 ? 1 : 0, join), "Subversion: Commit Will Split", Messages.getWarningIcon());
                return Messages.OK == isOk ? ReturnResult.COMMIT : ReturnResult.CANCEL;
            }
            return ReturnResult.COMMIT;
        }

        @Override
        public void includedChangesChanged() {
            myChanges = panel.getSelectedChanges();
        }

        @Override
        public void checkinSuccessful() {
            if (SvnConfiguration.getInstance(project).isAutoUpdateAfterCommit()) {
                final VirtualFile[] roots = ProjectLevelVcsManager.getInstance(project).getRootsUnderVcs(SvnVcs.getInstance(project));
                final List<FilePath> paths = new ArrayList<>();
                for (VirtualFile root : roots) {
                    boolean take = false;
                    for (VirtualFile commitRoot : commitRoots) {
                        if (VfsUtilCore.isAncestor(root, commitRoot, false)) {
                            take = true;
                            break;
                        }
                    }
                    if (take) {
                        paths.add(VcsUtil.getFilePath(root));
                    }
                }
                if (paths.isEmpty())
                    return;
                ApplicationManager.getApplication().invokeLater(() -> AutoSvnUpdater.run(new AutoSvnUpdater(project, paths.toArray(new FilePath[paths.size()])), ActionInfo.UPDATE.getActionName()), ModalityState.NON_MODAL);
            }
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FilePath(com.intellij.openapi.vcs.FilePath) LocalCommitExecutor(com.intellij.openapi.vcs.changes.LocalCommitExecutor) ArrayList(java.util.ArrayList) CheckinHandler(com.intellij.openapi.vcs.checkin.CheckinHandler) LocalCommitExecutor(com.intellij.openapi.vcs.changes.LocalCommitExecutor) CommitExecutor(com.intellij.openapi.vcs.changes.CommitExecutor) Project(com.intellij.openapi.project.Project) PairConsumer(com.intellij.util.PairConsumer) Collection(java.util.Collection) AutoSvnUpdater(org.jetbrains.idea.svn.update.AutoSvnUpdater) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with MultiMap

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

the class GrChangeSignatureProcessor method preprocessUsages.

@Override
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
    MultiMap<PsiElement, String> conflictDescriptions = new MultiMap<>();
    collectConflictsFromExtensions(refUsages, conflictDescriptions, myChangeInfo);
    final UsageInfo[] usagesIn = refUsages.get();
    RenameUtil.addConflictDescriptions(usagesIn, conflictDescriptions);
    Set<UsageInfo> usagesSet = new HashSet<>(Arrays.asList(usagesIn));
    RenameUtil.removeConflictUsages(usagesSet);
    if (!conflictDescriptions.isEmpty()) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            throw new ConflictsInTestsException(conflictDescriptions.values());
        }
        ConflictsDialog dialog = prepareConflictsDialog(conflictDescriptions, usagesIn);
        if (!dialog.showAndGet()) {
            if (dialog.isShowConflicts())
                prepareSuccessful();
            return false;
        }
    }
    refUsages.set(usagesSet.toArray(new UsageInfo[usagesSet.size()]));
    prepareSuccessful();
    return true;
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) PsiElement(com.intellij.psi.PsiElement) UsageInfo(com.intellij.usageView.UsageInfo) HashSet(com.intellij.util.containers.HashSet)

Example 3 with MultiMap

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

the class SvnCommittedListsZipper method groupLocations.

public Pair<List<RepositoryLocationGroup>, List<RepositoryLocation>> groupLocations(final List<RepositoryLocation> in) {
    final List<RepositoryLocationGroup> groups = new ArrayList<>();
    final List<RepositoryLocation> singles = new ArrayList<>();
    final MultiMap<SVNURL, RepositoryLocation> map = new MultiMap<>();
    for (RepositoryLocation location : in) {
        final SvnRepositoryLocation svnLocation = (SvnRepositoryLocation) location;
        final String url = svnLocation.getURL();
        final SVNURL root = SvnUtil.getRepositoryRoot(myVcs, url);
        if (root == null) {
            // should not occur
            LOG.info("repository root not found for location:" + location.toPresentableString());
            singles.add(location);
        } else {
            map.putValue(root, svnLocation);
        }
    }
    final Set<SVNURL> keys = map.keySet();
    for (SVNURL key : keys) {
        final Collection<RepositoryLocation> repositoryLocations = map.get(key);
        if (repositoryLocations.size() == 1) {
            singles.add(repositoryLocations.iterator().next());
        } else {
            final SvnRepositoryLocationGroup group = new SvnRepositoryLocationGroup(key, repositoryLocations);
            groups.add(group);
        }
    }
    return Pair.create(groups, singles);
}
Also used : SVNURL(org.tmatesoft.svn.core.SVNURL) ArrayList(java.util.ArrayList) RepositoryLocation(com.intellij.openapi.vcs.RepositoryLocation) MultiMap(com.intellij.util.containers.MultiMap) RepositoryLocationGroup(com.intellij.openapi.vcs.changes.committed.RepositoryLocationGroup)

Example 4 with MultiMap

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

the class ConvertClosureToMethodIntention method processIntention.

@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
    final GrField field;
    if (element.getParent() instanceof GrField) {
        field = (GrField) element.getParent();
    } else {
        final PsiReference ref = element.getReference();
        LOG.assertTrue(ref != null);
        PsiElement resolved = ref.resolve();
        if (resolved instanceof GrAccessorMethod) {
            resolved = ((GrAccessorMethod) resolved).getProperty();
        }
        LOG.assertTrue(resolved instanceof GrField);
        field = (GrField) resolved;
    }
    final HashSet<PsiReference> usages = new HashSet<>();
    usages.addAll(ReferencesSearch.search(field).findAll());
    final GrAccessorMethod[] getters = field.getGetters();
    for (GrAccessorMethod getter : getters) {
        usages.addAll(MethodReferencesSearch.search(getter).findAll());
    }
    final GrAccessorMethod setter = field.getSetter();
    if (setter != null) {
        usages.addAll(MethodReferencesSearch.search(setter).findAll());
    }
    final String fieldName = field.getName();
    LOG.assertTrue(fieldName != null);
    final Collection<PsiElement> fieldUsages = new HashSet<>();
    MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    for (PsiReference usage : usages) {
        final PsiElement psiElement = usage.getElement();
        if (PsiUtil.isMethodUsage(psiElement))
            continue;
        if (!GroovyLanguage.INSTANCE.equals(psiElement.getLanguage())) {
            conflicts.putValue(psiElement, GroovyIntentionsBundle.message("closure.is.accessed.outside.of.groovy", fieldName));
        } else {
            if (psiElement instanceof GrReferenceExpression) {
                fieldUsages.add(psiElement);
                if (PsiUtil.isAccessedForWriting((GrExpression) psiElement)) {
                    conflicts.putValue(psiElement, GroovyIntentionsBundle.message("write.access.to.closure.variable", fieldName));
                }
            } else if (psiElement instanceof GrArgumentLabel) {
                conflicts.putValue(psiElement, GroovyIntentionsBundle.message("field.is.used.in.argument.label", fieldName));
            }
        }
    }
    final PsiClass containingClass = field.getContainingClass();
    final GrExpression initializer = field.getInitializerGroovy();
    LOG.assertTrue(initializer != null);
    final PsiType type = initializer.getType();
    LOG.assertTrue(type instanceof GrClosureType);
    final GrSignature signature = ((GrClosureType) type).getSignature();
    final List<MethodSignature> signatures = GrClosureSignatureUtil.generateAllMethodSignaturesBySignature(fieldName, signature);
    for (MethodSignature s : signatures) {
        final PsiMethod method = MethodSignatureUtil.findMethodBySignature(containingClass, s, true);
        if (method != null) {
            conflicts.putValue(method, GroovyIntentionsBundle.message("method.with.signature.already.exists", GroovyPresentationUtil.getSignaturePresentation(s)));
        }
    }
    if (!conflicts.isEmpty()) {
        final ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts, () -> execute(field, fieldUsages));
        conflictsDialog.show();
        if (conflictsDialog.getExitCode() != DialogWrapper.OK_EXIT_CODE)
            return;
    }
    execute(field, fieldUsages);
}
Also used : GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) MethodSignature(com.intellij.psi.util.MethodSignature) GrArgumentLabel(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) GrAccessorMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod) MultiMap(com.intellij.util.containers.MultiMap) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) GrSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature) HashSet(com.intellij.util.containers.HashSet) GrClosureType(org.jetbrains.plugins.groovy.lang.psi.impl.GrClosureType)

Example 5 with MultiMap

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

the class MembersBasedPresenterImpl method getConflicts.

/**
   * Checks if one of destination classes already has members that should be moved, so conflict would take place.
   *
   * @return map of conflicts (if any)
   * @see #getDestClassesToCheckConflicts()
   */
@NotNull
protected final MultiMap<PyClass, PyMemberInfo<?>> getConflicts() {
    final MultiMap<PyClass, PyMemberInfo<?>> result = new MultiMap<>();
    final Collection<PyMemberInfo<PyElement>> memberInfos = myView.getSelectedMemberInfos();
    for (final PyClass destinationClass : getDestClassesToCheckConflicts()) {
        for (final PyMemberInfo<PyElement> pyMemberInfo : memberInfos) {
            if (pyMemberInfo.hasConflict(destinationClass)) {
                result.putValue(destinationClass, pyMemberInfo);
            }
        }
    }
    return result;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) MultiMap(com.intellij.util.containers.MultiMap) PyMemberInfo(com.jetbrains.python.refactoring.classes.membersManager.PyMemberInfo) PyElement(com.jetbrains.python.psi.PyElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MultiMap (com.intellij.util.containers.MultiMap)141 NotNull (org.jetbrains.annotations.NotNull)38 UsageInfo (com.intellij.usageView.UsageInfo)26 VirtualFile (com.intellij.openapi.vfs.VirtualFile)25 Project (com.intellij.openapi.project.Project)19 PsiElement (com.intellij.psi.PsiElement)18 Collection (java.util.Collection)17 ConflictsDialog (com.intellij.refactoring.ui.ConflictsDialog)16 Nullable (org.jetbrains.annotations.Nullable)16 Map (java.util.Map)15 Module (com.intellij.openapi.module.Module)11 File (java.io.File)11 ArrayList (java.util.ArrayList)11 ContainerUtil (com.intellij.util.containers.ContainerUtil)10 HashSet (com.intellij.util.containers.HashSet)10 THashSet (gnu.trove.THashSet)9 java.util (java.util)9 Pair (com.intellij.openapi.util.Pair)8 com.intellij.psi (com.intellij.psi)8 HashSet (java.util.HashSet)8