Search in sources :

Example 1 with ScInfixExpr

use of org.jetbrains.plugins.scala.lang.psi.api.expr.ScInfixExpr in project intellij by bazelbuild.

the class BlazeScalaSpecs2TestExprConfigurationProducer method testLocation.

@Nullable
private static TestLocation testLocation(ConfigurationContext context) {
    // Handled by SM runner.
    if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) {
        return null;
    }
    ScInfixExpr testCase = Specs2Utils.getContainingTestExprOrScope(context.getPsiLocation());
    if (testCase == null) {
        return null;
    }
    ScTypeDefinition testClass = PsiTreeUtil.getParentOfType(testCase, ScTypeDefinition.class);
    if (testClass == null) {
        return null;
    }
    TestSize testSize = TestSizeAnnotationMap.getTestSize(testClass);
    TargetInfo target = RunUtil.targetForTestClass(testClass, testSize);
    if (target == null) {
        return null;
    }
    return new TestLocation(target, testClass, testCase);
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) ScInfixExpr(org.jetbrains.plugins.scala.lang.psi.api.expr.ScInfixExpr) ScTypeDefinition(org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTypeDefinition) TestSize(com.google.idea.blaze.base.dependencies.TestSize) Nullable(javax.annotation.Nullable)

Example 2 with ScInfixExpr

use of org.jetbrains.plugins.scala.lang.psi.api.expr.ScInfixExpr 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)

Example 3 with ScInfixExpr

use of org.jetbrains.plugins.scala.lang.psi.api.expr.ScInfixExpr in project intellij by bazelbuild.

the class BlazeScalaTestLocator method findTestCase.

@SuppressWarnings("rawtypes")
private List<Location> findTestCase(Project project, String path) {
    String[] parts = path.split(SmRunnerUtils.TEST_NAME_PARTS_SPLITTER, 2);
    if (parts.length < 2) {
        return ImmutableList.of();
    }
    String className = parts[0];
    String testName = parts[1];
    PsiClass testClass = ClassUtil.findPsiClass(PsiManager.getInstance(project), className);
    for (ScInfixExpr testCase : PsiTreeUtil.findChildrenOfType(testClass, ScInfixExpr.class)) {
        if (TestNodeProvider.isSpecs2TestExpr(testCase) && Objects.equal(Specs2Utils.getSpecs2ScopedTestName(testCase), testName)) {
            return ImmutableList.of(new PsiLocation<>(testCase));
        }
    }
    return ImmutableList.of();
}
Also used : ScInfixExpr(org.jetbrains.plugins.scala.lang.psi.api.expr.ScInfixExpr) PsiClass(com.intellij.psi.PsiClass)

Example 4 with ScInfixExpr

use of org.jetbrains.plugins.scala.lang.psi.api.expr.ScInfixExpr in project intellij by bazelbuild.

the class Specs2Utils method getSpecs2ScopedTestName.

@Nullable
public static String getSpecs2ScopedTestName(ScInfixExpr testCase) {
    String testName = getSpecs2TestName(testCase);
    if (testName == null) {
        return null;
    }
    ScInfixExpr testScope = getContainingTestScope(testCase);
    if (testScope == null) {
        return testName;
    }
    String scopeName = getSpecs2ScopeName(testScope);
    if (scopeName == null) {
        return testName;
    }
    return scopeName + SmRunnerUtils.TEST_NAME_PARTS_SPLITTER + testName;
}
Also used : ScInfixExpr(org.jetbrains.plugins.scala.lang.psi.api.expr.ScInfixExpr) Nullable(javax.annotation.Nullable)

Aggregations

ScInfixExpr (org.jetbrains.plugins.scala.lang.psi.api.expr.ScInfixExpr)4 Nullable (javax.annotation.Nullable)3 TargetInfo (com.google.idea.blaze.base.dependencies.TargetInfo)1 TestSize (com.google.idea.blaze.base.dependencies.TestSize)1 PsiClass (com.intellij.psi.PsiClass)1 PsiElement (com.intellij.psi.PsiElement)1 ScFunctionDefinition (org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition)1 ScClass (org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScClass)1 ScTypeDefinition (org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTypeDefinition)1