Search in sources :

Example 1 with ScClass

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;
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) ArrayList(java.util.ArrayList) BlazeConfigurationNameBuilder(com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder) ScClass(org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScClass)

Example 2 with ScClass

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;
}
Also used : PsiElement(com.intellij.psi.PsiElement) ScClass(org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScClass) Nullable(javax.annotation.Nullable)

Example 3 with ScClass

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;
}
Also used : ScInfixExpr(org.jetbrains.plugins.scala.lang.psi.api.expr.ScInfixExpr) ScFunctionDefinition(org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition) PsiElement(com.intellij.psi.PsiElement) ScClass(org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScClass) Nullable(javax.annotation.Nullable)

Aggregations

ScClass (org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScClass)3 PsiElement (com.intellij.psi.PsiElement)2 Nullable (javax.annotation.Nullable)2 TargetInfo (com.google.idea.blaze.base.dependencies.TargetInfo)1 BlazeConfigurationNameBuilder (com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder)1 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)1 ArrayList (java.util.ArrayList)1 ScInfixExpr (org.jetbrains.plugins.scala.lang.psi.api.expr.ScInfixExpr)1 ScFunctionDefinition (org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition)1