Search in sources :

Example 6 with MultiMap

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

the class ExtractClosureFromMethodProcessor method preprocessUsages.

@Override
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
    UsageInfo[] usagesIn = refUsages.get();
    MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    final GrStatement[] statements = myHelper.getStatements();
    for (GrStatement statement : statements) {
        GroovyIntroduceParameterUtil.detectAccessibilityConflicts(statement, usagesIn, conflicts, false, myProject);
    }
    for (UsageInfo info : usagesIn) {
        if (info instanceof OtherLanguageUsageInfo) {
            final String lang = CommonRefactoringUtil.htmlEmphasize(info.getElement().getLanguage().getDisplayName());
            conflicts.putValue(info.getElement(), GroovyRefactoringBundle.message("cannot.process.usage.in.language.{0}", lang));
        }
    }
    if (!myMethod.hasModifierProperty(PsiModifier.PRIVATE)) {
        final AnySupers anySupers = new AnySupers();
        for (GrStatement statement : statements) {
            statement.accept(anySupers);
        }
        if (anySupers.containsSupers()) {
            for (UsageInfo usageInfo : usagesIn) {
                if (!(usageInfo.getElement() instanceof PsiMethod) && !(usageInfo instanceof InternalUsageInfo)) {
                    if (!PsiTreeUtil.isAncestor(myMethod.getContainingClass(), usageInfo.getElement(), false)) {
                        conflicts.putValue(statements[0], RefactoringBundle.message("parameter.initializer.contains.0.but.not.all.calls.to.method.are.in.its.class", CommonRefactoringUtil.htmlEmphasize(PsiKeyword.SUPER)));
                        break;
                    }
                }
            }
        }
    }
    if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
        throw new ConflictsInTestsException(conflicts.values());
    }
    if (!conflicts.isEmpty()) {
        final ConflictsDialog conflictsDialog = prepareConflictsDialog(conflicts, usagesIn);
        if (!conflictsDialog.showAndGet()) {
            if (conflictsDialog.isShowConflicts())
                prepareSuccessful();
            return false;
        }
    }
    prepareSuccessful();
    return true;
}
Also used : GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement) MultiMap(com.intellij.util.containers.MultiMap) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) UsageInfo(com.intellij.usageView.UsageInfo) NoConstructorClassUsageInfo(com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo) DefaultConstructorImplicitUsageInfo(com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo) AnySupers(org.jetbrains.plugins.groovy.refactoring.util.AnySupers)

Example 7 with MultiMap

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

the class GroovyInlineLocalProcessor method preprocessUsages.

@Override
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
    final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    final UsageInfo[] usages = refUsages.get();
    for (UsageInfo usage : usages) {
        collectConflicts(usage.getReference(), conflicts);
    }
    return showConflicts(conflicts, usages);
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) PsiElement(com.intellij.psi.PsiElement) UsageInfo(com.intellij.usageView.UsageInfo)

Example 8 with MultiMap

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

the class MavenProjectsTree method resolve.

public void resolve(@NotNull Project project, @NotNull Collection<MavenProject> mavenProjects, @NotNull MavenGeneralSettings generalSettings, @NotNull MavenEmbeddersManager embeddersManager, @NotNull MavenConsole console, @NotNull ResolveContext context, @NotNull MavenProgressIndicator process) throws MavenProcessCanceledException {
    MultiMap<File, MavenProject> projectMultiMap = groupByBasedir(mavenProjects);
    for (Map.Entry<File, Collection<MavenProject>> entry : projectMultiMap.entrySet()) {
        String baseDir = entry.getKey().getPath();
        MavenEmbedderWrapper embedder = embeddersManager.getEmbedder(MavenEmbeddersManager.FOR_DEPENDENCIES_RESOLVE, baseDir, baseDir);
        try {
            embedder.customizeForResolve(getWorkspaceMap(), console, process, generalSettings.isAlwaysUpdateSnapshots());
            doResolve(project, entry.getValue(), generalSettings, embedder, context, process);
        } finally {
            embeddersManager.release(embedder);
        }
    }
}
Also used : MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) VirtualFile(com.intellij.openapi.vfs.VirtualFile) MultiMap(com.intellij.util.containers.MultiMap)

Example 9 with MultiMap

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

the class MavenProjectsTree method downloadSourcesAndJavadocs.

public MavenArtifactDownloader.DownloadResult downloadSourcesAndJavadocs(@NotNull Project project, @NotNull Collection<MavenProject> projects, @Nullable Collection<MavenArtifact> artifacts, boolean downloadSources, boolean downloadDocs, @NotNull MavenEmbeddersManager embeddersManager, @NotNull MavenConsole console, @NotNull MavenProgressIndicator process) throws MavenProcessCanceledException {
    MultiMap<File, MavenProject> projectMultiMap = groupByBasedir(projects);
    MavenArtifactDownloader.DownloadResult result = new MavenArtifactDownloader.DownloadResult();
    for (Map.Entry<File, Collection<MavenProject>> entry : projectMultiMap.entrySet()) {
        String baseDir = entry.getKey().getPath();
        MavenEmbedderWrapper embedder = embeddersManager.getEmbedder(MavenEmbeddersManager.FOR_DOWNLOAD, baseDir, baseDir);
        try {
            embedder.customizeForResolve(console, process);
            MavenArtifactDownloader.DownloadResult result1 = MavenArtifactDownloader.download(project, this, projects, artifacts, downloadSources, downloadDocs, embedder, process);
            for (MavenProject each : projects) {
                fireArtifactsDownloaded(each);
            }
            result.resolvedDocs.addAll(result1.resolvedDocs);
            result.resolvedSources.addAll(result1.resolvedSources);
            result.unresolvedDocs.addAll(result1.unresolvedDocs);
            result.unresolvedSources.addAll(result1.unresolvedSources);
        } finally {
            embeddersManager.release(embedder);
        }
    }
    return result;
}
Also used : MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) VirtualFile(com.intellij.openapi.vfs.VirtualFile) MultiMap(com.intellij.util.containers.MultiMap)

Example 10 with MultiMap

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

the class MavenDuplicateDependenciesInspection method checkManagedDependencies.

private static void checkManagedDependencies(@NotNull MavenDomProjectModel projectModel, @NotNull DomElementAnnotationHolder holder) {
    MultiMap<DependencyConflictId, MavenDomDependency> duplicates = MultiMap.createSet();
    collect(duplicates, projectModel.getDependencyManagement().getDependencies());
    for (Map.Entry<DependencyConflictId, Collection<MavenDomDependency>> entry : duplicates.entrySet()) {
        Collection<MavenDomDependency> set = entry.getValue();
        if (set.size() <= 1)
            continue;
        for (MavenDomDependency dependency : set) {
            holder.createProblem(dependency, HighlightSeverity.WARNING, "Duplicated dependency");
        }
    }
}
Also used : DependencyConflictId(org.jetbrains.idea.maven.dom.DependencyConflictId) MultiMap(com.intellij.util.containers.MultiMap) MavenDomDependency(org.jetbrains.idea.maven.dom.model.MavenDomDependency)

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