Search in sources :

Example 21 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class BlazePyTestConfigurationProducer method doIsConfigFromContext.

@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null || !BlazeCommandName.TEST.equals(handlerState.getCommandState().getCommand())) {
        return false;
    }
    PsiElement element = selectedPsiElement(context);
    if (element == null) {
        return false;
    }
    if (!(element.getContainingFile() instanceof PyFile)) {
        return false;
    }
    TargetInfo testTarget = TestTargetHeuristic.testTargetForPsiElement(element);
    if (testTarget == null || !testTarget.label.equals(configuration.getTarget())) {
        return false;
    }
    String filter = testLocation(element).testFilter();
    String filterFlag = handlerState.getTestFilterFlag();
    return (filterFlag == null && filter == null) || Objects.equals(filterFlag, BlazeFlags.TEST_FILTER + "=" + filter);
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PyFile(com.jetbrains.python.psi.PyFile) PsiElement(com.intellij.psi.PsiElement)

Example 22 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class BlazeGoBinaryConfigurationProducer method doIsConfigFromContext.

@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null || !BlazeCommandName.RUN.equals(handlerState.getCommandState().getCommand())) {
        return false;
    }
    PsiFile file = getMainFile(context);
    if (file == null) {
        return false;
    }
    TargetInfo binaryTarget = getTargetLabel(file);
    return binaryTarget != null && binaryTarget.label.equals(configuration.getTarget());
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiFile(com.intellij.psi.PsiFile)

Example 23 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class BlazeGoBinaryConfigurationProducer method getTargetLabel.

@Nullable
private static TargetInfo getTargetLabel(PsiFile psiFile) {
    BlazeProjectData projectData = BlazeProjectDataManager.getInstance(psiFile.getProject()).getBlazeProjectData();
    if (projectData == null) {
        return null;
    }
    VirtualFile vf = psiFile.getVirtualFile();
    if (vf == null) {
        return null;
    }
    File file = new File(vf.getPath());
    return SourceToTargetMap.getInstance(psiFile.getProject()).getRulesForSourceFile(file).stream().map(projectData.targetMap::get).filter(Objects::nonNull).filter(t -> t.kind.languageClass.equals(LanguageClass.GO)).filter(t -> t.kind.ruleType.equals(RuleType.BINARY)).map(TargetIdeInfo::toTargetInfo).findFirst().orElse(null);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) RuleType(com.google.idea.blaze.base.model.primitives.RuleType) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) GoFile(com.goide.psi.GoFile) BlazeCommandRunConfigurationType(com.google.idea.blaze.base.run.BlazeCommandRunConfigurationType) VirtualFile(com.intellij.openapi.vfs.VirtualFile) BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) BlazeCommandName(com.google.idea.blaze.base.command.BlazeCommandName) Objects(java.util.Objects) GoRunUtil(com.goide.runconfig.GoRunUtil) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) SourceToTargetMap(com.google.idea.blaze.base.targetmaps.SourceToTargetMap) PsiElement(com.intellij.psi.PsiElement) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) PsiFile(com.intellij.psi.PsiFile) BlazeRunConfigurationProducer(com.google.idea.blaze.base.run.producers.BlazeRunConfigurationProducer) Ref(com.intellij.openapi.util.Ref) Nullable(javax.annotation.Nullable) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) GoFile(com.goide.psi.GoFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiFile(com.intellij.psi.PsiFile) Nullable(javax.annotation.Nullable)

Example 24 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class BlazeGoBinaryConfigurationProducer method doSetupConfigFromContext.

@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    PsiFile file = getMainFile(context);
    if (file == null) {
        return false;
    }
    TargetInfo binaryTarget = getTargetLabel(file);
    if (binaryTarget == null) {
        return false;
    }
    configuration.setTargetInfo(binaryTarget);
    sourceElement.set(file);
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    handlerState.getCommandState().setCommand(BlazeCommandName.RUN);
    configuration.setGeneratedName();
    return true;
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiFile(com.intellij.psi.PsiFile)

Example 25 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class BlazeGoTestConfigurationProducer method testLocation.

@Nullable
private static TestLocation testLocation(ConfigurationContext context) {
    // Handled by SM runner.
    if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) {
        return null;
    }
    PsiElement element = GoRunUtil.getContextElement(context);
    if (element == null) {
        return null;
    }
    PsiFile file = element.getContainingFile();
    if (!(file instanceof GoFile) || !GoTestFinder.isTestFile(file)) {
        return null;
    }
    TargetInfo testTarget = TestTargetHeuristic.testTargetForPsiElement(element);
    return testTarget != null ? new TestLocation(testTarget, (GoFile) file, GoTestFinder.findTestFunctionInContext(element)) : null;
}
Also used : GoFile(com.goide.psi.GoFile) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) Nullable(javax.annotation.Nullable)

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