use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazeScalaMainClassRunConfigurationProducer method doSetupConfigFromContext.
@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
ScObject mainObject = getMainObject(context);
if (mainObject == null) {
return false;
}
Option<PsiMethod> mainMethod = ScalaMainMethodUtil.findMainMethod(mainObject);
if (mainMethod.isEmpty()) {
sourceElement.set(mainObject);
} else {
sourceElement.set(mainMethod.get());
}
TargetIdeInfo target = getTarget(context.getProject(), mainObject);
if (target == null) {
return false;
}
configuration.setTargetInfo(target.toTargetInfo());
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.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazeScalaMainClassRunConfigurationProducer method doIsConfigFromContext.
@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
if (!Objects.equals(handlerState.getCommandState().getCommand(), BlazeCommandName.RUN)) {
return false;
}
ScObject mainObject = getMainObject(context);
if (mainObject == null) {
return false;
}
TargetIdeInfo target = getTarget(context.getProject(), mainObject);
return target != null && Objects.equals(configuration.getTarget(), target.key.label);
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazePyBinaryConfigurationProducer 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;
}
Location<?> location = context.getLocation();
if (location == null) {
return false;
}
PsiElement element = location.getPsiElement();
PsiFile file = element.getContainingFile();
if (!(file instanceof PyFile)) {
return false;
}
TargetInfo binaryTarget = getTargetLabel(file);
if (binaryTarget == null) {
return false;
}
return binaryTarget.label.equals(configuration.getTarget());
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazePyTestConfigurationProducer method doSetupConfigFromContext.
@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
PsiElement element = selectedPsiElement(context);
if (element == null) {
return false;
}
PsiFile file = element.getContainingFile();
if (!(file instanceof PyFile) || !PyTestUtils.isTestFile((PyFile) file)) {
return false;
}
TargetInfo testTarget = TestTargetHeuristic.testTargetForPsiElement(element);
if (testTarget == null) {
return false;
}
configuration.setTargetInfo(testTarget);
TestLocation testLocation = testLocation(element);
sourceElement.set(testLocation.sourceElement(file));
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
handlerState.getCommandState().setCommand(BlazeCommandName.TEST);
// remove conflicting flags from initial configuration
List<String> flags = new ArrayList<>(handlerState.getBlazeFlagsState().getRawFlags());
flags.removeIf((flag) -> flag.startsWith(BlazeFlags.TEST_FILTER));
String filter = testLocation.testFilter();
if (filter != null) {
flags.add(BlazeFlags.TEST_FILTER + "=" + filter);
}
handlerState.getBlazeFlagsState().setRawFlags(flags);
BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
nameBuilder.setTargetString(filter != null ? String.format("%s (%s)", filter, testTarget.label.toString()) : testTarget.label.toString());
configuration.setName(nameBuilder.build());
// don't revert to generated name
configuration.setNameChangedByUser(true);
return true;
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class AllInPackageBlazeConfigurationProducer method doSetupConfigFromContext.
@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
PsiDirectory dir = getTestDirectory(context);
if (dir == null) {
return false;
}
WorkspaceRoot root = WorkspaceRoot.fromProject(context.getProject());
WorkspacePath packagePath = getWorkspaceRelativeDirectoryPath(root, dir);
if (packagePath == null) {
return false;
}
sourceElement.set(dir);
configuration.setTarget(TargetExpression.allFromPackageRecursive(packagePath));
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
handlerState.getCommandState().setCommand(BlazeCommandName.TEST);
configuration.setGeneratedName();
return true;
}
Aggregations