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);
}
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());
}
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);
}
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;
}
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;
}
Aggregations