use of com.google.idea.blaze.base.model.primitives.TargetExpression 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.TargetExpression 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";
}
}
use of com.google.idea.blaze.base.model.primitives.TargetExpression in project intellij by bazelbuild.
the class BlazeRunConfigurationSyncListener method labelsWithConfigs.
/**
* Collects a set of all the Blaze labels that have an associated run configuration.
*/
private static Set<Label> labelsWithConfigs(Project project) {
List<RunConfiguration> configurations = RunManager.getInstance(project).getAllConfigurationsList();
Set<Label> labelsWithConfigs = Sets.newHashSet();
for (RunConfiguration configuration : configurations) {
if (configuration instanceof BlazeRunConfiguration) {
BlazeRunConfiguration blazeRunConfiguration = (BlazeRunConfiguration) configuration;
TargetExpression target = blazeRunConfiguration.getTarget();
if (target instanceof Label) {
labelsWithConfigs.add((Label) target);
}
}
}
return labelsWithConfigs;
}
use of com.google.idea.blaze.base.model.primitives.TargetExpression in project intellij by bazelbuild.
the class WildcardTargetPatternTest method testRecursiveWildcardPatternAllTargets.
@Test
public void testRecursiveWildcardPatternAllTargets() {
TargetExpression target = TargetExpression.fromStringSafe("//java/com/google/...:all-targets");
WildcardTargetPattern wildcardPattern = WildcardTargetPattern.fromExpression(target);
assertThat(wildcardPattern).isNotNull();
assertThat(wildcardPattern.coversPackage(new WorkspacePath("java/com/google"))).isTrue();
assertThat(wildcardPattern.coversPackage(new WorkspacePath("java/com/google/foo"))).isTrue();
assertThat(wildcardPattern.isRecursive()).isTrue();
assertThat(wildcardPattern.getBasePackage()).isEqualTo(new WorkspacePath("java/com/google"));
assertThat(wildcardPattern.rulesOnly()).isFalse();
}
use of com.google.idea.blaze.base.model.primitives.TargetExpression in project intellij by bazelbuild.
the class WildcardTargetPatternTest method testNonRecursiveAllTargetsWildcardPattern.
@Test
public void testNonRecursiveAllTargetsWildcardPattern() {
TargetExpression target = TargetExpression.fromStringSafe("//java/com/google:*");
WildcardTargetPattern wildcardPattern = WildcardTargetPattern.fromExpression(target);
assertThat(wildcardPattern).isNotNull();
assertThat(wildcardPattern.coversPackage(new WorkspacePath("java/com/google"))).isTrue();
assertThat(wildcardPattern.coversPackage(new WorkspacePath("java/com/google/foo"))).isFalse();
assertThat(wildcardPattern.isRecursive()).isFalse();
assertThat(wildcardPattern.getBasePackage()).isEqualTo(new WorkspacePath("java/com/google"));
assertThat(wildcardPattern.rulesOnly()).isFalse();
}
Aggregations