/* * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.intellij.packageDependencies.actions; import com.intellij.analysis.AnalysisScope; import com.intellij.analysis.AnalysisScopeBundle; import com.intellij.notification.NotificationGroup; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.ToolWindowId; import com.intellij.packageDependencies.BackwardDependenciesBuilder; import com.intellij.packageDependencies.DependenciesBuilder; import com.intellij.packageDependencies.DependencyVisitorFactory; import com.intellij.psi.PsiFile; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.util.containers.HashSet; import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.List; import java.util.Set; /** * @author nik */ public class AnalyzeDependenciesOnSpecifiedTargetHandler extends DependenciesHandlerBase { private static final NotificationGroup NOTIFICATION_GROUP = NotificationGroup.toolWindowGroup("Dependencies", ToolWindowId.DEPENDENCIES); private final GlobalSearchScope myTargetScope; public AnalyzeDependenciesOnSpecifiedTargetHandler(@NotNull Project project, @NotNull AnalysisScope scope, @NotNull GlobalSearchScope targetScope) { super(project, Collections.singletonList(scope), new HashSet<>()); myTargetScope = targetScope; } @Override protected String getProgressTitle() { return AnalysisScopeBundle.message("package.dependencies.progress.title"); } @Override protected String getPanelDisplayName(AnalysisScope scope) { return AnalysisScopeBundle.message("package.dependencies.on.toolwindow.title", scope.getDisplayName(), myTargetScope.getDisplayName()); } @Override protected String getPanelDisplayName(List<DependenciesBuilder> builders) { return getPanelDisplayName(getForwardScope(builders)); } private static AnalysisScope getForwardScope(List<DependenciesBuilder> builders) { final DependenciesBuilder builder = builders.get(0); return builder instanceof BackwardDependenciesBuilder ? ((BackwardDependenciesBuilder)builder).getForwardScope() : builder.getScope(); } @Override protected boolean shouldShowDependenciesPanel(List<DependenciesBuilder> builders) { for (DependenciesBuilder builder : builders) { for (Set<PsiFile> files : builder.getDependencies().values()) { if (!files.isEmpty()) { return true; } } } final String source = StringUtil.decapitalize(getForwardScope(builders).getDisplayName()); final String target = StringUtil.decapitalize(myTargetScope.getDisplayName()); String message = AnalysisScopeBundle.message("no.dependencies.found.message", source, target); if (DependencyVisitorFactory.VisitorOptions.fromSettings(myProject).skipImports()) { message += " "; message += AnalysisScopeBundle.message("dependencies.in.imports.message"); } NOTIFICATION_GROUP.createNotification(message, MessageType.INFO).notify(myProject); return false; } @Override protected DependenciesBuilder createDependenciesBuilder(AnalysisScope scope) { return new BackwardDependenciesBuilder(myProject, new AnalysisScope(myTargetScope, myProject), scope); } }