Search in sources :

Example 1 with BuildTargetFinder

use of com.google.idea.blaze.base.sync.BuildTargetFinder in project intellij by bazelbuild.

the class PartialSyncAction method getTargets.

private static List<TargetExpression> getTargets(Project project, @Nullable VirtualFile virtualFile) {
    if (virtualFile == null) {
        return ImmutableList.of();
    }
    List<TargetExpression> targets = Lists.newArrayList();
    WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
    SourceToTargetMap.getInstance(project);
    if (!virtualFile.isDirectory()) {
        targets.addAll(SourceToTargetMap.getInstance(project).getTargetsToBuildForSourceFile(new File(virtualFile.getPath())));
    }
    if (targets.isEmpty()) {
        ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
        if (projectViewSet != null) {
            BuildSystem buildSystem = Blaze.getBuildSystem(project);
            ImportRoots importRoots = ImportRoots.builder(workspaceRoot, buildSystem).add(projectViewSet).build();
            BuildTargetFinder buildTargetFinder = new BuildTargetFinder(project, workspaceRoot, importRoots);
            TargetExpression targetExpression = buildTargetFinder.findTargetForFile(new File(virtualFile.getPath()));
            if (targetExpression != null) {
                targets.add(targetExpression);
            }
        }
    }
    return targets;
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) BuildSystem(com.google.idea.blaze.base.settings.Blaze.BuildSystem) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) BuildTargetFinder(com.google.idea.blaze.base.sync.BuildTargetFinder)

Aggregations

TargetExpression (com.google.idea.blaze.base.model.primitives.TargetExpression)1 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)1 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)1 BuildSystem (com.google.idea.blaze.base.settings.Blaze.BuildSystem)1 BuildTargetFinder (com.google.idea.blaze.base.sync.BuildTargetFinder)1 ImportRoots (com.google.idea.blaze.base.sync.projectview.ImportRoots)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 File (java.io.File)1