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