Search in sources :

Example 76 with Location

use of com.intellij.execution.Location in project intellij by bazelbuild.

the class BlazeJavaAbstractTestCaseConfigurationProducer method getAbstractLocation.

@Nullable
private static AbstractTestLocation getAbstractLocation(ConfigurationContext context) {
    if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) {
        // handled by a different producer
        return null;
    }
    PsiMethod method = getTestMethod(context);
    if (method != null) {
        PsiClass psiClass = method.getContainingClass();
        return hasTestSubclasses(psiClass) ? new AbstractTestLocation(psiClass, method) : null;
    }
    Location location = context.getLocation();
    if (location == null) {
        return null;
    }
    location = JavaExecutionUtil.stepIntoSingleClass(location);
    if (location == null) {
        return null;
    }
    PsiClass psiClass = PsiTreeUtil.getParentOfType(location.getPsiElement(), PsiClass.class, false);
    return hasTestSubclasses(psiClass) ? new AbstractTestLocation(psiClass, null) : null;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) Location(com.intellij.execution.Location) Nullable(javax.annotation.Nullable)

Example 77 with Location

use of com.intellij.execution.Location in project intellij by bazelbuild.

the class BlazeAndroidTestClassRunConfigurationProducer method doIsConfigFromContext.

@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
    final Location contextLocation = context.getLocation();
    assert contextLocation != null;
    final Location location = JavaExecutionUtil.stepIntoSingleClass(contextLocation);
    if (location == null) {
        return false;
    }
    if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) {
        // handled by a different producer
        return false;
    }
    if (JUnitConfigurationUtil.isMultipleElementsSelected(context)) {
        return false;
    }
    Location<PsiMethod> methodLocation = ProducerUtils.getMethodLocation(contextLocation);
    if (methodLocation != null) {
        return false;
    }
    PsiClass testClass = JUnitUtil.getTestClass(location);
    if (testClass == null) {
        return false;
    }
    return checkIfAttributesAreTheSame(configuration, testClass);
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) Location(com.intellij.execution.Location)

Example 78 with Location

use of com.intellij.execution.Location in project intellij by bazelbuild.

the class BlazeAndroidTestMethodRunConfigurationProducer method doSetupConfigFromContext.

@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) {
        // handled by a different producer
        return false;
    }
    if (JUnitConfigurationUtil.isMultipleElementsSelected(context)) {
        return false;
    }
    final Location contextLocation = context.getLocation();
    assert contextLocation != null;
    Location<PsiMethod> methodLocation = ProducerUtils.getMethodLocation(contextLocation);
    if (methodLocation == null) {
        return false;
    }
    final PsiMethod psiMethod = methodLocation.getPsiElement();
    sourceElement.set(psiMethod);
    final PsiClass containingClass = psiMethod.getContainingClass();
    if (containingClass == null) {
        return false;
    }
    TargetInfo target = RunUtil.targetForTestClass(containingClass, null);
    if (target == null) {
        return false;
    }
    if (!Kind.ANDROID_TEST.equals(target.getKind())) {
        return false;
    }
    configuration.setTargetInfo(target);
    BlazeAndroidTestRunConfigurationState configState = configuration.getHandlerStateIfType(BlazeAndroidTestRunConfigurationState.class);
    if (configState == null) {
        return false;
    }
    configState.setTestingType(AndroidTestRunConfiguration.TEST_METHOD);
    configState.setClassName(containingClass.getQualifiedName());
    configState.setMethodName(psiMethod.getName());
    configuration.setGeneratedName();
    return true;
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) Location(com.intellij.execution.Location)

Example 79 with Location

use of com.intellij.execution.Location in project intellij by bazelbuild.

the class BlazeAndroidTestMethodRunConfigurationProducer method doIsConfigFromContext.

@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
    if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) {
        // handled by a different producer
        return false;
    }
    if (JUnitConfigurationUtil.isMultipleElementsSelected(context)) {
        return false;
    }
    final Location contextLocation = context.getLocation();
    assert contextLocation != null;
    Location<PsiMethod> methodLocation = ProducerUtils.getMethodLocation(contextLocation);
    if (methodLocation == null) {
        return false;
    }
    final PsiMethod psiMethod = methodLocation.getPsiElement();
    final PsiClass containingClass = psiMethod.getContainingClass();
    if (containingClass == null) {
        return false;
    }
    return checkIfAttributesAreTheSame(configuration, psiMethod);
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) Location(com.intellij.execution.Location)

Aggregations

Location (com.intellij.execution.Location)79 PsiClass (com.intellij.psi.PsiClass)27 PsiElement (com.intellij.psi.PsiElement)26 VirtualFile (com.intellij.openapi.vfs.VirtualFile)20 PsiMethod (com.intellij.psi.PsiMethod)19 PsiLocation (com.intellij.execution.PsiLocation)18 Project (com.intellij.openapi.project.Project)18 PsiMemberParameterizedLocation (com.intellij.execution.junit2.PsiMemberParameterizedLocation)17 MethodLocation (com.intellij.execution.junit2.info.MethodLocation)16 Module (com.intellij.openapi.module.Module)14 Nullable (org.jetbrains.annotations.Nullable)9 PsiFile (com.intellij.psi.PsiFile)8 ArrayList (java.util.ArrayList)8 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)7 SMTestProxy (com.intellij.execution.testframework.sm.runner.SMTestProxy)6 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (javax.annotation.Nullable)5 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)4 PatternConfigurationProducer (com.intellij.execution.junit.PatternConfigurationProducer)4 Kind (com.google.idea.blaze.base.model.primitives.Kind)3