Search in sources :

Example 6 with TestSize

use of com.google.idea.blaze.base.dependencies.TestSize in project intellij by bazelbuild.

the class BlazeJavaTestMethodConfigurationProducer method getSelectedMethodContext.

@Nullable
private static TestMethodContext getSelectedMethodContext(ConfigurationContext context) {
    if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) {
        // handled by a different producer
        return null;
    }
    final List<PsiMethod> selectedMethods = TestMethodSelectionUtil.getSelectedMethods(context);
    if (selectedMethods == null) {
        return null;
    }
    assert selectedMethods.size() > 0;
    final PsiMethod firstMethod = selectedMethods.get(0);
    final PsiClass containingClass = firstMethod.getContainingClass();
    if (containingClass == null) {
        return null;
    }
    for (PsiMethod method : selectedMethods) {
        if (!containingClass.equals(method.getContainingClass())) {
            return null;
        }
    }
    TestSize testSize = TestSizeAnnotationMap.getTestSize(firstMethod);
    TargetInfo target = RunUtil.targetForTestClass(containingClass, testSize);
    if (target == null) {
        return null;
    }
    String testFilter = BlazeJUnitTestFilterFlags.testFilterForClassAndMethods(containingClass, selectedMethods);
    if (testFilter == null) {
        return null;
    }
    // Sort so multiple configurations created with different selection orders are the same.
    List<String> methodNames = selectedMethods.stream().map(PsiMethod::getName).sorted().collect(Collectors.toList());
    final String testFilterFlag = BlazeFlags.TEST_FILTER + "=" + testFilter;
    return new TestMethodContext(firstMethod, containingClass, methodNames, testFilterFlag, target);
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) TestSize(com.google.idea.blaze.base.dependencies.TestSize) Nullable(javax.annotation.Nullable)

Example 7 with TestSize

use of com.google.idea.blaze.base.dependencies.TestSize in project intellij by bazelbuild.

the class TestSizeAnnotationMap method getTestSize.

@Nullable
public static TestSize getTestSize(PsiClass psiClass) {
    PsiModifierList psiModifierList = psiClass.getModifierList();
    if (psiModifierList == null) {
        return null;
    }
    PsiAnnotation[] annotations = psiModifierList.getAnnotations();
    TestSize testSize = getTestSize(annotations);
    if (testSize == null) {
        return null;
    }
    return testSize;
}
Also used : PsiAnnotation(com.intellij.psi.PsiAnnotation) TestSize(com.google.idea.blaze.base.dependencies.TestSize) PsiModifierList(com.intellij.psi.PsiModifierList) Nullable(javax.annotation.Nullable)

Example 8 with TestSize

use of com.google.idea.blaze.base.dependencies.TestSize in project intellij by bazelbuild.

the class TestSizeAnnotationMap method getTestSize.

@Nullable
public static TestSize getTestSize(PsiMethod psiMethod) {
    PsiAnnotation[] annotations = psiMethod.getModifierList().getAnnotations();
    TestSize testSize = getTestSize(annotations);
    if (testSize != null) {
        return testSize;
    }
    return getTestSize(psiMethod.getContainingClass());
}
Also used : PsiAnnotation(com.intellij.psi.PsiAnnotation) TestSize(com.google.idea.blaze.base.dependencies.TestSize) Nullable(javax.annotation.Nullable)

Example 9 with TestSize

use of com.google.idea.blaze.base.dependencies.TestSize in project intellij by bazelbuild.

the class IdeInfoFromProtobuf method makeTestIdeInfo.

private static TestIdeInfo makeTestIdeInfo(IntellijIdeInfo.TestInfo testInfo) {
    String size = testInfo.getSize();
    TestSize testSize = TestSize.DEFAULT_RULE_TEST_SIZE;
    if (!Strings.isNullOrEmpty(size)) {
        switch(size) {
            case "small":
                testSize = TestSize.SMALL;
                break;
            case "medium":
                testSize = TestSize.MEDIUM;
                break;
            case "large":
                testSize = TestSize.LARGE;
                break;
            case "enormous":
                testSize = TestSize.ENORMOUS;
                break;
            default:
                break;
        }
    }
    return new TestIdeInfo(testSize);
}
Also used : TestSize(com.google.idea.blaze.base.dependencies.TestSize) TestIdeInfo(com.google.idea.blaze.base.ideinfo.TestIdeInfo)

Aggregations

TestSize (com.google.idea.blaze.base.dependencies.TestSize)9 Nullable (javax.annotation.Nullable)7 TargetInfo (com.google.idea.blaze.base.dependencies.TargetInfo)4 PsiAnnotation (com.intellij.psi.PsiAnnotation)3 PsiClass (com.intellij.psi.PsiClass)3 TestIdeInfo (com.google.idea.blaze.base.ideinfo.TestIdeInfo)1 BlazeConfigurationNameBuilder (com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder)1 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)1 PsiMethod (com.intellij.psi.PsiMethod)1 PsiModifierList (com.intellij.psi.PsiModifierList)1 ArrayList (java.util.ArrayList)1 ScInfixExpr (org.jetbrains.plugins.scala.lang.psi.api.expr.ScInfixExpr)1 ScTypeDefinition (org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTypeDefinition)1