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