Search in sources :

Example 51 with TargetKey

use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.

the class AddLibraryTargetDirectoryToProjectViewAction method getDirectoryToAddForLibrary.

@Nullable
static WorkspacePath getDirectoryToAddForLibrary(Project project, Library library) {
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        return null;
    }
    BlazeJarLibrary blazeLibrary = LibraryActionHelper.findLibraryFromIntellijLibrary(project, blazeProjectData, library);
    if (blazeLibrary == null) {
        return null;
    }
    TargetKey originatingTarget = findOriginatingTargetForLibrary(blazeProjectData, blazeLibrary);
    if (originatingTarget == null) {
        return null;
    }
    TargetIdeInfo target = blazeProjectData.targetMap.get(originatingTarget);
    if (target == null) {
        return null;
    }
    // It makes no sense to add directories for java_imports and the like
    if (!target.kind.isOneOf(Kind.JAVA_LIBRARY, Kind.ANDROID_LIBRARY, Kind.PROTO_LIBRARY)) {
        return null;
    }
    if (target.buildFile == null) {
        return null;
    }
    File buildFile = new File(target.buildFile.getRelativePath());
    WorkspacePath workspacePath = new WorkspacePath(Strings.nullToEmpty(buildFile.getParent()));
    ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
    if (projectViewSet == null) {
        return null;
    }
    boolean exists = WorkspacePathUtil.isUnderAnyWorkspacePath(projectViewSet.listItems(DirectorySection.KEY).stream().filter(entry -> entry.included).map(entry -> entry.directory).collect(toList()), workspacePath);
    if (exists) {
        return null;
    }
    return workspacePath;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) DirectorySection(com.google.idea.blaze.base.projectview.section.sections.DirectorySection) Presentation(com.intellij.openapi.actionSystem.Presentation) ProjectViewManager(com.google.idea.blaze.base.projectview.ProjectViewManager) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) BlazeProjectAction(com.google.idea.blaze.base.actions.BlazeProjectAction) Strings(com.google.common.base.Strings) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) Library(com.intellij.openapi.roots.libraries.Library) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ImmutableList(com.google.common.collect.ImmutableList) BlazeSyncManager(com.google.idea.blaze.base.sync.BlazeSyncManager) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) Nullable(javax.annotation.Nullable) WorkspacePathUtil(com.google.idea.blaze.base.util.WorkspacePathUtil) Set(java.util.Set) Sets(com.google.common.collect.Sets) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ProjectViewEdit(com.google.idea.blaze.base.projectview.ProjectViewEdit) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) BlazeUserSettings(com.google.idea.blaze.base.settings.BlazeUserSettings) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ListSection(com.google.idea.blaze.base.projectview.section.ListSection) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 52 with TargetKey

use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.

the class BlazeGoGotoDeclarationHandler method resolveImportPath.

@Nullable
private static PsiElement resolveImportPath(Project project, String importPath) {
    BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (projectData == null) {
        return null;
    }
    Map<String, TargetKey> packageMap = BlazeGoRootsProvider.getPackageToTargetMap(project);
    if (packageMap == null) {
        return null;
    }
    TargetKey targetKey = packageMap.get(importPath);
    if (targetKey == null) {
        return null;
    }
    BuildReferenceManager buildReferenceManager = BuildReferenceManager.getInstance(project);
    PsiElement resolvedLabel = buildReferenceManager.resolveLabel(targetKey.label);
    if (resolvedLabel != null) {
        return resolvedLabel;
    }
    File blazePackage = WorkspaceHelper.resolveBlazePackage(project, targetKey.label);
    return buildReferenceManager.findBuildFile(blazePackage);
}
Also used : BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) BuildReferenceManager(com.google.idea.blaze.base.lang.buildfile.references.BuildReferenceManager) GoFile(com.goide.psi.GoFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) PsiElement(com.intellij.psi.PsiElement) Nullable(javax.annotation.Nullable)

Aggregations

TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)52 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)25 File (java.io.File)19 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)14 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)14 Nullable (javax.annotation.Nullable)12 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)11 List (java.util.List)11 Test (org.junit.Test)11 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)9 Project (com.intellij.openapi.project.Project)9 Map (java.util.Map)9 ImmutableList (com.google.common.collect.ImmutableList)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 Collection (java.util.Collection)8 Set (java.util.Set)8 Sets (com.google.common.collect.Sets)7 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)7 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)7 ExecutionException (java.util.concurrent.ExecutionException)7