Search in sources :

Example 1 with BlazePackage

use of com.google.idea.blaze.base.lang.buildfile.search.BlazePackage in project intellij by bazelbuild.

the class CopyBlazeTargetPathAction method getTargetBuildingFile.

/**
 * Find a BUILD target building the selected file, if relevant.
 */
@Nullable
private static Label getTargetBuildingFile(Project project, AnActionEvent e) {
    VirtualFile vf = e.getData(CommonDataKeys.VIRTUAL_FILE);
    BlazePackage parentPackage = BuildFileUtils.getBuildFile(project, vf);
    if (parentPackage == null) {
        return null;
    }
    PsiElement target = BuildFileUtils.findBuildTarget(project, parentPackage, new File(vf.getPath()));
    return target instanceof FuncallExpression ? ((FuncallExpression) target).resolveBuildLabel() : null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) BlazePackage(com.google.idea.blaze.base.lang.buildfile.search.BlazePackage) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiElement(com.intellij.psi.PsiElement) Nullable(javax.annotation.Nullable)

Example 2 with BlazePackage

use of com.google.idea.blaze.base.lang.buildfile.search.BlazePackage in project intellij by bazelbuild.

the class OpenCorrespondingBuildFile method updateForBlazeProject.

@Override
protected void updateForBlazeProject(Project project, AnActionEvent e) {
    Presentation presentation = e.getPresentation();
    DataContext dataContext = e.getDataContext();
    VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
    BlazePackage blazePackage = BuildFileUtils.getBuildFile(project, virtualFile);
    if (blazePackage != null && virtualFile.equals(blazePackage.buildFile.getVirtualFile())) {
        presentation.setEnabledAndVisible(false);
        return;
    }
    boolean enabled = blazePackage != null;
    presentation.setVisible(enabled || !ActionPlaces.isPopupPlace(e.getPlace()));
    presentation.setEnabled(enabled);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DataContext(com.intellij.openapi.actionSystem.DataContext) BlazePackage(com.google.idea.blaze.base.lang.buildfile.search.BlazePackage) Presentation(com.intellij.openapi.actionSystem.Presentation)

Example 3 with BlazePackage

use of com.google.idea.blaze.base.lang.buildfile.search.BlazePackage in project intellij by bazelbuild.

the class OpenCorrespondingBuildFile method navigateToTargetOrFile.

/**
 * Returns true if a target or BUILD file could be found and navigated to.
 */
private static void navigateToTargetOrFile(Project project, VirtualFile vf) {
    // First, find the parent BUILD file. We don't want to navigate to labels in other packages
    BlazePackage parentPackage = BuildFileUtils.getBuildFile(project, vf);
    if (parentPackage == null) {
        return;
    }
    // first, look for a specific target which includes this source file
    PsiElement target = BuildFileUtils.findBuildTarget(project, parentPackage, new File(vf.getPath()));
    if (target instanceof NavigatablePsiElement) {
        ((NavigatablePsiElement) target).navigate(true);
        return;
    }
    OpenFileAction.openFile(parentPackage.buildFile.getFile().getPath(), project);
}
Also used : BlazePackage(com.google.idea.blaze.base.lang.buildfile.search.BlazePackage) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiElement(com.intellij.psi.PsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement)

Example 4 with BlazePackage

use of com.google.idea.blaze.base.lang.buildfile.search.BlazePackage in project intellij by bazelbuild.

the class FileLookupData method packageLocalFileLookup.

@Nullable
public static FileLookupData packageLocalFileLookup(String originalLabel, StringLiteral element) {
    if (originalLabel.startsWith("/")) {
        return null;
    }
    BlazePackage blazePackage = element.getBlazePackage();
    BuildFile baseBuildFile = blazePackage != null ? blazePackage.buildFile : null;
    return packageLocalFileLookup(originalLabel, element, baseBuildFile, null);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) BlazePackage(com.google.idea.blaze.base.lang.buildfile.search.BlazePackage) Nullable(javax.annotation.Nullable)

Example 5 with BlazePackage

use of com.google.idea.blaze.base.lang.buildfile.search.BlazePackage in project intellij by bazelbuild.

the class LabelReference method bindToElement.

@Override
public PsiElement bindToElement(PsiElement element) throws IncorrectOperationException {
    PsiFile file = ResolveUtil.asFileSearch(element);
    if (file == null) {
        return super.bindToElement(element);
    }
    if (file.equals(resolve())) {
        return myElement;
    }
    BlazePackage currentPackageDir = myElement.getBlazePackage();
    if (currentPackageDir == null) {
        return myElement;
    }
    BlazePackage newPackageDir = BlazePackage.getContainingPackage(file);
    if (!currentPackageDir.equals(newPackageDir)) {
        return myElement;
    }
    String newRuleName = newPackageDir.getPackageRelativePath(file.getViewProvider().getVirtualFile().getPath());
    return handleRename(newRuleName);
}
Also used : BlazePackage(com.google.idea.blaze.base.lang.buildfile.search.BlazePackage) PsiFile(com.intellij.psi.PsiFile)

Aggregations

BlazePackage (com.google.idea.blaze.base.lang.buildfile.search.BlazePackage)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiElement (com.intellij.psi.PsiElement)3 Nullable (javax.annotation.Nullable)3 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)2 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)2 PsiFile (com.intellij.psi.PsiFile)2 File (java.io.File)2 BuildLookupElement (com.google.idea.blaze.base.lang.buildfile.completion.BuildLookupElement)1 LabelRuleLookupElement (com.google.idea.blaze.base.lang.buildfile.completion.LabelRuleLookupElement)1 Argument (com.google.idea.blaze.base.lang.buildfile.psi.Argument)1 BlazeFileType (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile.BlazeFileType)1 LoadStatement (com.google.idea.blaze.base.lang.buildfile.psi.LoadStatement)1 StringLiteral (com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral)1 PsiUtils (com.google.idea.blaze.base.lang.buildfile.psi.util.PsiUtils)1 ResolveUtil (com.google.idea.blaze.base.lang.buildfile.search.ResolveUtil)1 Label (com.google.idea.blaze.base.model.primitives.Label)1 ASTNode (com.intellij.lang.ASTNode)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 Presentation (com.intellij.openapi.actionSystem.Presentation)1