Search in sources :

Example 1 with TargetInfo

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());
    }
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) JBLabel(com.intellij.ui.components.JBLabel) Label(com.google.idea.blaze.base.model.primitives.Label) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression)

Example 2 with TargetInfo

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);
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData)

Example 3 with TargetInfo

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;
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) Nullable(javax.annotation.Nullable)

Example 4 with TargetInfo

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiFile(com.intellij.psi.PsiFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiFile(com.intellij.psi.PsiFile) Nullable(javax.annotation.Nullable)

Example 5 with TargetInfo

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"));
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) File(java.io.File) Test(org.junit.Test)

Aggregations

TargetInfo (com.google.idea.blaze.base.dependencies.TargetInfo)69 File (java.io.File)43 Test (org.junit.Test)40 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)19 PsiFile (com.intellij.psi.PsiFile)18 Nullable (javax.annotation.Nullable)15 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)14 PsiElement (com.intellij.psi.PsiElement)9 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)7 Label (com.google.idea.blaze.base.model.primitives.Label)7 PsiClass (com.intellij.psi.PsiClass)7 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)6 RuleType (com.google.idea.blaze.base.model.primitives.RuleType)6 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 Truth.assertThat (com.google.common.truth.Truth.assertThat)5 BlazeTestCase (com.google.idea.blaze.base.BlazeTestCase)5 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)5 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)5 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)5