use of com.google.idea.blaze.base.dependencies.TargetInfo 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.dependencies.TargetInfo in project intellij by bazelbuild.
the class ProjectTargetFinder method findTarget.
@Override
public Future<TargetInfo> findTarget(Project project, Label label) {
BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
TargetInfo target = projectData != null ? findTarget(projectData.targetMap, label) : null;
return Futures.immediateFuture(target);
}
use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.
the class TargetFinder method findTargetInfo.
/**
* Iterates through all {@link TargetFinder}s, returning the first immediately available, non-null
* result.
*/
@Nullable
static TargetInfo findTargetInfo(Project project, Label label) {
for (TargetFinder finder : EP_NAME.getExtensions()) {
Future<TargetInfo> future = finder.findTarget(project, label);
if (!future.isDone()) {
continue;
}
TargetInfo target = FuturesUtil.getIgnoringErrors(future);
if (target != null) {
return target;
}
}
return null;
}
use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.
the class TestTargetHeuristic method testTargetForPsiElement.
/**
* Finds a test rule associated with a given {@link PsiElement}.
*/
@Nullable
static TargetInfo testTargetForPsiElement(@Nullable PsiElement element) {
if (element == null) {
return null;
}
PsiFile psiFile = element.getContainingFile();
if (psiFile == null) {
return null;
}
VirtualFile vf = psiFile.getVirtualFile();
File file = vf != null ? new File(vf.getPath()) : null;
if (file == null) {
return null;
}
Project project = element.getProject();
Collection<TargetInfo> rules = SourceToTargetFinder.findTargetsForSourceFile(project, file, Optional.of(RuleType.TEST));
return chooseTestTargetForSourceFile(element.getProject(), psiFile, file, rules, null);
}
use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.
the class TestTargetHeuristicTest method testNoMatchFallBackToFirstTarget.
@Test
public void testNoMatchFallBackToFirstTarget() {
File source = workspaceRoot.fileForPath(new WorkspacePath("java/com/foo/FooTest.java"));
ImmutableList<TargetInfo> targets = ImmutableList.of(TargetIdeInfo.builder().setLabel("//bar:BarTest").setKind("java_test").setTestInfo(TestIdeInfo.builder().setTestSize(TestSize.MEDIUM)).build().toTargetInfo(), TargetIdeInfo.builder().setLabel("//foo:OtherTest").setKind("java_test").setTestInfo(TestIdeInfo.builder().setTestSize(TestSize.SMALL)).build().toTargetInfo());
TargetInfo match = TestTargetHeuristic.chooseTestTargetForSourceFile(getProject(), null, source, targets, TestSize.LARGE);
assertThat(match.label).isEqualTo(Label.create("//bar:BarTest"));
}
Aggregations