use of org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScClass in project intellij by bazelbuild.
the class BlazeScalaTestClassConfigurationProducer method doSetupConfigFromContext.
@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
ScClass testClass = getTestClass(context);
if (testClass == null) {
return false;
}
sourceElement.set(testClass);
TargetInfo target = RunUtil.targetForTestClass(testClass, TestSizeAnnotationMap.getTestSize(testClass));
if (target == null) {
return false;
}
configuration.setTargetInfo(target);
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
List<String> flags = new ArrayList<>(handlerState.getBlazeFlagsState().getRawFlags());
flags.removeIf((flag) -> flag.startsWith(BlazeFlags.TEST_FILTER));
flags.add(getTestFilterFlag(testClass));
handlerState.getBlazeFlagsState().setRawFlags(flags);
handlerState.getCommandState().setCommand(BlazeCommandName.TEST);
BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
nameBuilder.setTargetString(testClass.getName());
configuration.setName(nameBuilder.build());
// don't revert to generated name
configuration.setNameChangedByUser(true);
return true;
}
use of org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScClass in project intellij by bazelbuild.
the class BlazeScalaTestClassConfigurationProducer method getTestClass.
@Nullable
private static ScClass getTestClass(Location<?> location) {
PsiElement element = location.getPsiElement();
ScClass testClass;
if (element instanceof ScClass) {
testClass = (ScClass) element;
} else {
testClass = PsiTreeUtil.getParentOfType(element, ScClass.class);
}
if (testClass != null && isTestClass(testClass)) {
return testClass;
}
return null;
}
use of org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScClass in project intellij by bazelbuild.
the class BlazeScalaTestRunLineMarkerContributor method getInfo.
@Nullable
@Override
public Info getInfo(PsiElement element) {
if (isIdentifier(element)) {
PsiElement testElement = element.getParent();
if (testElement instanceof ScClass) {
return getInfo((ScClass) testElement, null, super.getInfo(element));
}
ScClass testClass = PsiTreeUtil.getParentOfType(testElement, ScClass.class);
if (testClass == null) {
return null;
}
if (testElement instanceof ScFunctionDefinition) {
return getInfo(testClass, testElement, super.getInfo(element));
}
if (testElement.getParent() instanceof ScInfixExpr) {
ScInfixExpr infixExpr = (ScInfixExpr) testElement.getParent();
if (infixExpr.operation().equals(testElement)) {
return getInfo(testClass, infixExpr, super.getInfo(element));
}
}
}
return null;
}
Aggregations