use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.
the class LabelUtils method createLabelFromString.
/**
* Canonicalizes the label (to the form [@external_workspace]//packagePath:packageRelativeTarget).
* Returns null if the string does not represent a valid label.
*/
@Nullable
public static Label createLabelFromString(@Nullable BlazePackage blazePackage, @Nullable String labelString) {
if (labelString == null) {
return null;
}
int colonIndex = labelString.indexOf(':');
if (isAbsolute(labelString)) {
if (colonIndex == -1) {
// add the implicit rule name
labelString += ":" + PathUtil.getFileName(labelString);
}
return Label.createIfValid(labelString);
}
// package-relative label of the form '[:]relativePath'
if (colonIndex > 0 || blazePackage == null) {
return null;
}
Label packageLabel = blazePackage.getPackageLabel();
return packageLabel != null ? packageLabel.withTargetName(labelString.substring(colonIndex + 1)) : null;
}
use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.
the class BlazePackage method getBuildLabelForChild.
/**
* Formats the child file path as a BUILD label (i.e. "//package_path[:relative_path]")
*/
@Nullable
public Label getBuildLabelForChild(String filePath) {
Label parentPackage = getPackageLabel();
if (parentPackage == null) {
return null;
}
String relativePath = getPackageRelativePath(filePath);
return parentPackage.withTargetName(relativePath);
}
use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.
the class ProjectViewLabelReference method handleElementRename.
@Override
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
String currentString = myElement.getText();
Label label = getLabel(currentString);
if (label == null) {
return myElement;
}
String ruleName = label.targetName().toString();
String newRuleName = newElementName;
// handle subdirectories
int lastSlashIndex = ruleName.lastIndexOf('/');
if (lastSlashIndex != -1) {
newRuleName = ruleName.substring(0, lastSlashIndex + 1) + newElementName;
}
String packageString = LabelUtils.getPackagePathComponent(currentString);
if (packageString.isEmpty() && !currentString.contains(":")) {
return handleRename(newRuleName);
}
return handleRename(packageString + ":" + newRuleName);
}
use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.
the class BlazeCommandRunConfiguration method updateTargetKindAsync.
/**
* Queries the kind of the current target pattern, possibly asynchronously.
*
* @param asyncCallback if the kind is updated asynchronously, this will be run after the kind is
* updated. If it's updated synchronously, this will not be run.
*/
void updateTargetKindAsync(@Nullable Runnable asyncCallback) {
TargetExpression expr = parseTarget(targetPattern);
if (!(expr instanceof Label)) {
updateTargetKind(null);
return;
}
Label label = (Label) expr;
ListenableFuture<TargetInfo> future = TargetFinder.findTargetInfoFuture(getProject(), label);
if (future.isDone()) {
updateTargetKind(FuturesUtil.getIgnoringErrors(future));
} else {
updateTargetKind(null);
future.addListener(() -> {
updateTargetKind(FuturesUtil.getIgnoringErrors(future));
if (asyncCallback != null) {
asyncCallback.run();
}
}, MoreExecutors.directExecutor());
}
}
use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.
the class BlazeCommandRunConfiguration method getTargetKindName.
/**
* @return The {@link Kind} name, if the target is a known rule. Otherwise, "target pattern" if it
* is a general {@link TargetExpression}, "unknown rule" if it is a {@link Label} without a
* known rule, and "unknown target" if there is no target.
*/
private String getTargetKindName() {
Kind kind = targetKind;
if (kind != null) {
return kind.toString();
}
TargetExpression target = parseTarget(targetPattern);
if (target instanceof Label) {
return "unknown rule";
} else if (target != null) {
return "target pattern";
} else {
return "unknown target";
}
}
Aggregations