Search in sources :

Example 76 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.

the class BlazeGoTestEventsHandlerTest method testSuiteLocationResolvesToSingleSourceFile.

@Test
public void testSuiteLocationResolvesToSingleSourceFile() {
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//foo/bar:foo_test").setKind("go_test").setBuildFile(src("foo/bar/BUILD")).addSource(src("foo/bar/foo_test.go")).setGoInfo(GoIdeInfo.builder().addSources(ImmutableList.of(src("foo/bar/foo_test.go"))).setImportPath("google3/foo/bar/foo"))).build();
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(new BlazeProjectData(0L, targetMap, null, null, new WorkspacePathResolverImpl(workspaceRoot), location -> workspaceRoot.fileForPath(new WorkspacePath(location.getRelativePath())), new WorkspaceLanguageSettings(WorkspaceType.GO, ImmutableSet.of(LanguageClass.GO)), null, null)));
    GoFile goFile = (GoFile) workspace.createPsiFile(new WorkspacePath("foo/bar/foo_test.go"), "package foo", "import \"testing\"", "func TestFoo(t *testing.T) {}");
    workspace.createFile(new WorkspacePath("foo/bar/BUILD"), "go_test(", "    name = 'foo_test',", "    srcs = ['foo_test.go'],", ")");
    String url = handler.suiteLocationUrl(null, "foo/bar/foo_test");
    Location<?> location = getLocation(url);
    assertThat(location).isNotNull();
    assertThat(location.getPsiElement()).isEqualTo(goFile);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) GoFile(com.goide.psi.GoFile) WorkspacePathResolverImpl(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Test(org.junit.Test)

Example 77 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData 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 78 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.

the class AddLibraryTargetDirectoryToProjectViewAttachSourcesProvider method getActions.

@NotNull
@Override
public Collection<AttachSourcesAction> getActions(List<LibraryOrderEntry> orderEntries, final PsiFile psiFile) {
    Project project = psiFile.getProject();
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        return ImmutableList.of();
    }
    List<Library> librariesToAttachSourceTo = Lists.newArrayList();
    for (LibraryOrderEntry orderEntry : orderEntries) {
        Library library = orderEntry.getLibrary();
        WorkspacePath workspacePath = AddLibraryTargetDirectoryToProjectViewAction.getDirectoryToAddForLibrary(project, library);
        if (workspacePath == null) {
            continue;
        }
        librariesToAttachSourceTo.add(library);
    }
    if (librariesToAttachSourceTo.isEmpty()) {
        return ImmutableList.of();
    }
    return ImmutableList.of(new AttachSourcesAction() {

        @Override
        public String getName() {
            return "Add Source Directories To Project View";
        }

        @Override
        public String getBusyText() {
            return "Adding directories...";
        }

        @Override
        public ActionCallback perform(List<LibraryOrderEntry> orderEntriesContainingFile) {
            AddLibraryTargetDirectoryToProjectViewAction.addDirectoriesToProjectView(project, librariesToAttachSourceTo);
            return ActionCallback.DONE;
        }
    });
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Project(com.intellij.openapi.project.Project) ActionCallback(com.intellij.openapi.util.ActionCallback) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Library(com.intellij.openapi.roots.libraries.Library) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) NotNull(org.jetbrains.annotations.NotNull)

Example 79 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData in project intellij by bazelbuild.

the class BlazeSourceJarNavigationPolicy method getPsiFile.

@Nullable
private Result<PsiFile> getPsiFile(ClsFileImpl file) {
    Project project = file.getProject();
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        return null;
    }
    VirtualFile root = getSourceJarRoot(project, blazeProjectData, file);
    if (root == null) {
        return null;
    }
    return getSourceFileResult(file, root);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Nullable(javax.annotation.Nullable)

Example 80 with BlazeProjectData

use of com.google.idea.blaze.base.model.BlazeProjectData 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

BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)82 File (java.io.File)31 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)28 Nullable (javax.annotation.Nullable)24 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)23 Test (org.junit.Test)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)17 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)17 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)15 BlazeSyncParams (com.google.idea.blaze.base.sync.BlazeSyncParams)13 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)13 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)13 Project (com.intellij.openapi.project.Project)13 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)11 ImmutableList (com.google.common.collect.ImmutableList)10 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)10 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)8 List (java.util.List)8 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)7