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);
}
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;
}
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;
}
});
}
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);
}
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);
}
Aggregations