com.intellij.execution.Location Java Examples

The following examples show how to use com.intellij.execution.Location. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlazeGoTestEventsHandlerTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private Location<?> getLocation(String url) {
  String protocol = VirtualFileManager.extractProtocol(url);
  if (protocol == null) {
    return null;
  }
  String path = VirtualFileManager.extractPath(url);
  assertThat(handler.getTestLocator()).isNotNull();
  @SuppressWarnings("rawtypes")
  List<Location> locations =
      handler
          .getTestLocator()
          .getLocation(protocol, path, getProject(), GlobalSearchScope.allScope(getProject()));
  assertThat(locations).hasSize(1);
  return locations.get(0);
}
 
Example #2
Source File: BlazeAndroidTestLocator.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public List<Location> getLocation(
    String protocol, String path, Project project, GlobalSearchScope scope) {
  if (!protocol.equals(SmRunnerUtils.GENERIC_SUITE_PROTOCOL)) {
    return ImmutableList.of();
  }
  String[] split = path.split(SmRunnerUtils.TEST_NAME_PARTS_SPLITTER);
  List<PsiClass> classes = findClasses(project, scope, split[0]);
  if (classes.isEmpty()) {
    return ImmutableList.of();
  }
  if (split.length <= 1) {
    return classes.stream().map(PsiLocation::new).collect(Collectors.toList());
  }

  String methodName = split[1];
  List<Location> results = new ArrayList<>();
  for (PsiClass psiClass : classes) {
    PsiMethod method = findTestMethod(psiClass, methodName);
    if (method != null) {
      results.add(new PsiLocation<>(method));
    }
  }
  return results.isEmpty() ? ImmutableList.of(new PsiLocation<>(classes.get(0))) : results;
}
 
Example #3
Source File: SMTestProxy.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected Location getLocation(@Nonnull Project project, @Nonnull GlobalSearchScope searchScope, String locationUrl) {
  if (locationUrl != null && myLocator != null) {
    String protocolId = VirtualFileManager.extractProtocol(locationUrl);
    if (protocolId != null) {
      String path = VirtualFileManager.extractPath(locationUrl);
      if (!DumbService.isDumb(project) || DumbService.isDumbAware(myLocator)) {
        return DumbService.getInstance(project).computeWithAlternativeResolveEnabled(() -> {
          List<Location> locations = myLocator.getLocation(protocolId, path, myMetainfo, project, searchScope);
          return !locations.isEmpty() ? locations.get(0) : null;
        });
      }
    }
  }

  return null;
}
 
Example #4
Source File: DartTestLocationProviderZ.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Nullable
protected Location<PsiElement> getLocationByLineAndColumn(@NotNull final PsiFile file, final int line, final int column) {
  final Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
  if (document == null) return null;

  final int offset = document.getLineStartOffset(line) + column;
  final PsiElement element = file.findElementAt(offset);
  final PsiElement parent1 = element == null ? null : element.getParent();
  final PsiElement parent2 = parent1 instanceof DartId ? parent1.getParent() : null;
  final PsiElement parent3 = parent2 instanceof DartReferenceExpression ? parent2.getParent() : null;
  if (parent3 instanceof DartCallExpression) {
    if (TestUtil.isTest((DartCallExpression)parent3) || TestUtil.isGroup((DartCallExpression)parent3)) {
      return new PsiLocation<>(parent3);
    }
  }
  return null;
}
 
Example #5
Source File: MongoScriptRunConfigurationProducer.java    From nosql4idea with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
protected RunnerAndConfigurationSettings createConfigurationByElement(Location location, ConfigurationContext configurationContext) {
    sourceFile = location.getPsiElement().getContainingFile();
    if (sourceFile != null && sourceFile.getFileType().getName().toLowerCase().contains("javascript")) {
        Project project = sourceFile.getProject();

        VirtualFile file = sourceFile.getVirtualFile();

        RunnerAndConfigurationSettings settings = cloneTemplateConfiguration(project, configurationContext);

        MongoRunConfiguration runConfiguration = (MongoRunConfiguration) settings.getConfiguration();
        runConfiguration.setName(file.getName());

        runConfiguration.setScriptPath(file.getPath());

        Module module = ModuleUtil.findModuleForPsiElement(location.getPsiElement());
        if (module != null) {
            runConfiguration.setModule(module);
        }

        return settings;
    }
    return null;
}
 
Example #6
Source File: ScalaTestContextProvider.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private static ScClass getTestClass(ConfigurationContext context) {
  Location<?> location = context.getLocation();
  if (location == null) {
    return null;
  }
  location = JavaExecutionUtil.stepIntoSingleClass(location);
  if (location == null) {
    return null;
  }
  if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) {
    // handled by a different producer
    return null;
  }
  return getTestClass(location);
}
 
Example #7
Source File: ExternalSystemTasksPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@javax.annotation.Nullable
private Location buildLocation() {
  if (mySelectedTaskProvider == null) {
    return null;
  }
  ExternalTaskExecutionInfo task = mySelectedTaskProvider.produce();
  if (task == null) {
    return null;
  }

  String projectPath = task.getSettings().getExternalProjectPath();
  String name = myExternalSystemId.getReadableName() + projectPath + StringUtil.join(task.getSettings().getTaskNames(), " ");
  // We create a dummy text file instead of re-using external system file in order to avoid clashing with other configuration producers.
  // For example gradle files are enhanced groovy scripts but we don't want to run them via regular IJ groovy script runners.
  // Gradle tooling api should be used for running gradle tasks instead. IJ execution sub-system operates on Location objects
  // which encapsulate PsiElement and groovy runners are automatically applied if that PsiElement IS-A GroovyFile.
  PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText(name, PlainTextFileType.INSTANCE, "nichts");

  return new ExternalSystemTaskLocation(myProject, file, task);
}
 
Example #8
Source File: BlazeFilterExistingRunConfigurationProducer.java    From intellij with Apache License 2.0 6 votes vote down vote up
private static Optional<String> getTestFilter(ConfigurationContext context) {
  RunConfiguration base = context.getOriginalConfiguration(null);
  if (!(base instanceof BlazeCommandRunConfiguration)) {
    return Optional.empty();
  }
  ImmutableList<? extends TargetExpression> targets =
      ((BlazeCommandRunConfiguration) base).getTargets();
  if (targets.isEmpty()) {
    return Optional.empty();
  }
  List<Location<?>> selectedElements = SmRunnerUtils.getSelectedSmRunnerTreeElements(context);
  if (selectedElements.isEmpty()) {
    return Optional.empty();
  }
  Optional<BlazeTestEventsHandler> testEventsHandler =
      BlazeTestEventsHandler.getHandlerForTargets(context.getProject(), targets);
  return testEventsHandler.map(
      handler -> handler.getTestFilter(context.getProject(), selectedElements));
}
 
Example #9
Source File: ProducerUtils.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
public static Location<PsiMethod> getMethodLocation(Location<?> contextLocation) {
  Location<PsiMethod> methodLocation = getTestMethod(contextLocation);
  if (methodLocation == null) {
    return null;
  }

  if (contextLocation instanceof PsiMemberParameterizedLocation) {
    PsiClass containingClass =
        ((PsiMemberParameterizedLocation) contextLocation).getContainingClass();
    if (containingClass != null) {
      methodLocation =
          MethodLocation.elementInClass(methodLocation.getPsiElement(), containingClass);
    }
  }
  return methodLocation;
}
 
Example #10
Source File: ProducerUtils.java    From intellij with Apache License 2.0 6 votes vote down vote up
/** Same as {@link JUnitUtil#getTestClass}, but handles classes outside the project. */
@Nullable
public static PsiClass getTestClass(final Location<?> location) {
  for (Iterator<Location<PsiClass>> iterator = location.getAncestors(PsiClass.class, false);
      iterator.hasNext(); ) {
    final Location<PsiClass> classLocation = iterator.next();
    if (isTestClass(classLocation.getPsiElement())) {
      return classLocation.getPsiElement();
    }
  }
  PsiElement element = location.getPsiElement();
  if (element instanceof PsiClassOwner) {
    PsiClass[] classes = ((PsiClassOwner) element).getClasses();
    if (classes.length == 1 && isTestClass(classes[0])) {
      return classes[0];
    }
  }
  return null;
}
 
Example #11
Source File: TestMethodSelectionUtil.java    From intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Get a test method which is considered selected in the given context, belonging to a
 * non-abstract class. The context location may be the method itself, or anywhere inside the
 * method.
 *
 * @param context The context to search for a test method in.
 * @return A test method, or null if none are found.
 */
@Nullable
public static PsiMethod getIndirectlySelectedMethod(@NotNull ConfigurationContext context) {
  final Location<?> contextLocation = context.getLocation();
  if (contextLocation == null) {
    return null;
  }
  Iterator<Location<PsiMethod>> locationIterator =
      contextLocation.getAncestors(PsiMethod.class, false);
  while (locationIterator.hasNext()) {
    Location<PsiMethod> methodLocation = locationIterator.next();
    if (JUnitUtil.isTestMethod(methodLocation)) {
      return methodLocation.getPsiElement();
    }
  }
  return null;
}
 
Example #12
Source File: JavaBinaryContextProvider.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private static PsiClass getMainClass(ConfigurationContext context) {
  Location location = context.getLocation();
  if (location == null) {
    return null;
  }
  location = JavaExecutionUtil.stepIntoSingleClass(location);
  if (location == null) {
    return null;
  }
  PsiElement element = location.getPsiElement();
  if (!element.isPhysical()) {
    return null;
  }
  return ApplicationConfigurationType.getMainClass(element);
}
 
Example #13
Source File: PreferredProducerFind.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Deprecated
@SuppressWarnings("deprecation")
private static List<RuntimeConfigurationProducer> findAllProducers(Location location, ConfigurationContext context) {
  //todo load configuration types if not already loaded
  ConfigurationType.CONFIGURATION_TYPE_EP.getExtensionList();
  final List<RuntimeConfigurationProducer> configurationProducers = RuntimeConfigurationProducer.RUNTIME_CONFIGURATION_PRODUCER.getExtensionList();
  final ArrayList<RuntimeConfigurationProducer> producers = new ArrayList<>();
  for (final RuntimeConfigurationProducer prototype : configurationProducers) {
    final RuntimeConfigurationProducer producer;
    try {
      producer = prototype.createProducer(location, context);
    }
    catch (AbstractMethodError e) {
      LOG.error(new ExtensionException(prototype.getClass()));
      continue;
    }
    if (producer.getConfiguration() != null) {
      LOG.assertTrue(producer.getSourceElement() != null, producer);
      producers.add(producer);
    }
  }
  return producers;
}
 
Example #14
Source File: BlazeJUnitTestFilterFlags.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
public static String testFilterForClassesAndMethods(
    Map<PsiClass, Collection<Location<?>>> methodsPerClass, JUnitVersion version) {
  List<String> classFilters = new ArrayList<>();
  for (Entry<PsiClass, Collection<Location<?>>> entry : methodsPerClass.entrySet()) {
    ParameterizedTestInfo parameterizedTestInfo =
        JUnitParameterizedClassHeuristic.getParameterizedTestInfo(entry.getKey());
    String filter =
        testFilterForClassAndMethods(
            entry.getKey(),
            version,
            extractMethodFilters(entry.getValue()),
            parameterizedTestInfo);
    if (filter == null) {
      return null;
    }
    classFilters.add(filter);
  }
  classFilters.sort(String::compareTo);
  return version == JUnitVersion.JUNIT_4
      ? String.join("|", classFilters)
      : String.join(",", classFilters);
}
 
Example #15
Source File: BlazeGoWebTestEventsHandlerTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private Location<?> getLocation(String url) {
  String protocol = VirtualFileManager.extractProtocol(url);
  if (protocol == null) {
    return null;
  }
  String path = VirtualFileManager.extractPath(url);
  assertThat(handler.getTestLocator()).isNotNull();
  @SuppressWarnings("rawtypes")
  List<Location> locations =
      handler
          .getTestLocator()
          .getLocation(protocol, path, getProject(), GlobalSearchScope.allScope(getProject()));
  assertThat(locations).hasSize(1);
  return locations.get(0);
}
 
Example #16
Source File: QuickRunMavenGoalAction.java    From MavenHelper with Apache License 2.0 6 votes vote down vote up
@NotNull
private AnActionEvent getAnActionEvent(@NotNull AnActionEvent e) {
	DataContext dataContext = new DataContext() {
		@Nullable
		@Override
		public Object getData(@NotNull String s) {
			if (Location.DATA_KEY.is(s)) {
				PsiFile data = LangDataKeys.PSI_FILE.getData(e.getDataContext());
				ConfigurationContext fromContext = ConfigurationContext.getFromContext(e.getDataContext());
				PsiFile psiFile = PsiManager.getInstance(e.getProject()).findFile(mavenProject.mavenProject.getFile());
				return new MavenGoalLocation(e.getProject(), psiFile, goal.parse(data, fromContext));
			}
			return e.getDataContext().getData(s);
		}
	};

	return AnActionEvent.createFromDataContext("MavenRunHelper.CreateRunConfiguration", e.getPresentation(), dataContext);
}
 
Example #17
Source File: RunConfigurationProducer.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Searches the list of existing run configurations to find one created from this context. Returns one if found, or tries to create
 * a new configuration from this context if not found.
 *
 * @param context contains the information about a location in the source code.
 * @return a configuration (new or existing) matching the context, or null if the context is not applicable to this producer.
 */
@javax.annotation.Nullable
public ConfigurationFromContext findOrCreateConfigurationFromContext(ConfigurationContext context) {
  Location location = context.getLocation();
  if (location == null) {
    return null;
  }

  ConfigurationFromContext fromContext = createConfigurationFromContext(context);
  if (fromContext != null) {
    final PsiElement psiElement = fromContext.getSourceElement();
    final Location<PsiElement> _location = PsiLocation.fromPsiElement(psiElement, location.getModule());
    if (_location != null) {
      // replace with existing configuration if any
      final RunManager runManager = RunManager.getInstance(context.getProject());
      final RunnerAndConfigurationSettings settings = findExistingConfiguration(context);
      if (settings != null) {
        fromContext.setConfigurationSettings(settings);
      } else {
        runManager.setUniqueNameIfNeed(fromContext.getConfiguration());
      }
    }
  }

  return fromContext;
}
 
Example #18
Source File: BlazePythonTestEventsHandler.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public String getTestFilter(Project project, List<Location<?>> testLocations) {
  // python test runner parses filters of the form "class1.method1 class2.method2 ..."
  // parameterized test cases can cause the same class.method combination to be present
  // multiple times, so we use a set
  Set<String> filters = new LinkedHashSet<>();
  for (Location<?> location : testLocations) {
    String filter = getFilter(location.getPsiElement());
    if (filter != null) {
      filters.add(filter);
    }
  }
  if (filters.isEmpty()) {
    return null;
  }
  return String.format(
      "%s=%s",
      BlazeFlags.TEST_FILTER, BlazeParametersListUtil.encodeParam(Joiner.on(' ').join(filters)));
}
 
Example #19
Source File: BlazePythonTestLocator.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public List<Location> getLocation(
    String protocol, String path, Project project, GlobalSearchScope scope) {
  if (protocol.equals(SmRunnerUtils.GENERIC_SUITE_PROTOCOL)) {
    return findTestClass(project, scope, path);
  }
  if (protocol.equals(SmRunnerUtils.GENERIC_TEST_PROTOCOL)) {
    path = StringUtil.trimStart(path, PY_TESTCASE_PREFIX);
    String[] components = path.split("\\.|::");
    if (components.length < 2) {
      return ImmutableList.of();
    }
    return findTestMethod(
        project, scope, components[components.length - 2], components[components.length - 1]);
  }
  return ImmutableList.of();
}
 
Example #20
Source File: BlazeCidrTestEventsHandler.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public String getTestFilter(Project project, List<Location<?>> testLocations) {
  List<String> filters =
      testLocations.stream()
          .map(l -> GoogleTestLocation.findGoogleTest(l, project))
          .map(l -> l != null ? l.getTestFilter() : null)
          .filter(Objects::nonNull)
          .collect(toImmutableList());
  if (filters.isEmpty()) {
    return null;
  }
  return String.format(
      "%s=%s",
      BlazeFlags.TEST_FILTER, BlazeParametersListUtil.encodeParam(Joiner.on(':').join(filters)));
}
 
Example #21
Source File: BlazeScalaTestLocator.java    From intellij with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #22
Source File: BlazeJavaTestEventsHandlerTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Test
public void testMethodLocationResolves() {
  PsiFile javaFile =
      workspace.createPsiFile(
          new WorkspacePath("java/com/google/lib/JavaClass.java"),
          "package com.google.lib;",
          "public class JavaClass {",
          "  public void testMethod() {}",
          "}");
  PsiClass javaClass = ((PsiClassOwner) javaFile).getClasses()[0];
  PsiMethod method = javaClass.findMethodsByName("testMethod", false)[0];
  assertThat(method).isNotNull();

  String url =
      handler.testLocationUrl(
          Label.create("//java/com/google/lib:JavaClass"),
          null,
          null,
          "testMethod",
          "com.google.lib.JavaClass");
  Location<?> location = getLocation(url);
  assertThat(location.getPsiElement()).isEqualTo(method);
}
 
Example #23
Source File: TrackCoverageAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void selectSubCoverage() {
  final CoverageDataManager coverageDataManager = CoverageDataManager.getInstance(myProperties.getProject());
  final CoverageSuitesBundle currentSuite = coverageDataManager.getCurrentSuitesBundle();
  if (currentSuite != null) {
    final AbstractTestProxy test = myModel.getTreeView().getSelectedTest();
    List<String> testMethods = new ArrayList<String>();
    if (test != null && !test.isInProgress()) {
      final List<? extends AbstractTestProxy> list = test.getAllTests();
      for (AbstractTestProxy proxy : list) {
        final Location location = proxy.getLocation(myProperties.getProject(), myProperties.getScope());
        if (location != null) {
          final PsiElement element = location.getPsiElement();
          final String name = currentSuite.getCoverageEngine().getTestMethodName(element, proxy);
          if (name != null) {
            testMethods.add(name);
          }
        }
      }
    }
    coverageDataManager.selectSubCoverage(currentSuite, testMethods);
  }
}
 
Example #24
Source File: BlazeJavaWebTestEventsHandlerTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Test
public void testSuiteLocationResolves() {
  TargetMap targetMap =
      TargetMapBuilder.builder()
          .addTarget(
              TargetIdeInfo.builder()
                  .setLabel("//java/com/google/lib:JavaClass_chrome-linux")
                  .setKind("java_web_test")
                  .setBuildFile(src("java/com/google/lib/BUILD"))
                  .addDependency("//java/com/google/lib:JavaClass_wrapped_test"))
          .addTarget(
              TargetIdeInfo.builder()
                  .setLabel("//java/com/google/lib:JavaClass_wrapped_test")
                  .setKind("java_test")
                  .setBuildFile(src("java/com/google/lib/BUILD"))
                  .addSource(src("java/com/google/lib/JavaClass.java")))
          .build();

  registerProjectService(
      BlazeProjectDataManager.class,
      new MockBlazeProjectDataManager(
          MockBlazeProjectDataBuilder.builder(workspaceRoot).setTargetMap(targetMap).build()));

  PsiFile javaFile =
      workspace.createPsiFile(
          new WorkspacePath("java/com/google/lib/JavaClass.java"),
          "package com.google.lib;",
          "public class JavaClass {}");
  PsiClass javaClass = ((PsiClassOwner) javaFile).getClasses()[0];
  assertThat(javaClass).isNotNull();

  String url =
      handler.suiteLocationUrl(
          Label.create("//java/com/google/lib:JavaClass_chrome-linux"),
          RuleTypes.JAVA_WEB_TEST.getKind(),
          "com.google.lib.JavaClass");
  Location<?> location = getLocation(url);
  assertThat(location).isNotNull();
  assertThat(location.getPsiElement()).isEqualTo(javaClass);
}
 
Example #25
Source File: AndroidTestContextProvider.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public RunConfigurationContext getTestContext(ConfigurationContext context) {
  if (JUnitConfigurationUtil.isMultipleElementsSelected(context)) {
    return null;
  }
  Location<?> location = context.getLocation();
  if (location == null) {
    return null;
  }
  PsiMethod method = findTestMethod(location);
  PsiClass testClass =
      method != null ? method.getContainingClass() : JUnitUtil.getTestClass(location);
  return testClass != null ? AndroidTestContext.fromClassAndMethod(testClass, method) : null;
}
 
Example #26
Source File: GaugeExecutionProducer.java    From Intellij-Plugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isConfigurationFromContext(RunConfiguration configuration, ConfigurationContext context) {
    if (!(configuration.getType() instanceof GaugeRunTaskConfigurationType)) return false;
    Location location = context.getLocation();
    PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context.getDataContext());
    if (location == null || location.getVirtualFile() == null || element == null) return false;
    if (!isInSpecScope(context.getPsiLocation())) return false;
    String specsToExecute = ((GaugeRunConfiguration) configuration).getSpecsToExecute();
    return specsToExecute != null && (specsToExecute.equals(location.getVirtualFile().getPath()));
}
 
Example #27
Source File: BlazeJavaTestEventsHandler.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public String getTestFilter(Project project, List<Location<?>> testLocations) {
  Map<PsiClass, Collection<Location<?>>> failedClassesAndMethods = new HashMap<>();
  for (Location<?> location : testLocations) {
    appendTest(failedClassesAndMethods, location);
  }
  String filter =
      BlazeJUnitTestFilterFlags.testFilterForClassesAndMethods(failedClassesAndMethods);
  return filter != null ? BlazeFlags.TEST_FILTER + "=" + filter : null;
}
 
Example #28
Source File: BlazeAndroidTestEventsHandler.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public String getTestFilter(Project project, List<Location<?>> testLocations) {
  Map<PsiClass, Collection<Location<?>>> failedClassesAndMethods = new HashMap<>();
  for (Location<?> location : testLocations) {
    appendTest(failedClassesAndMethods, location);
  }
  // the android test runner always runs with JUnit4
  String filter =
      BlazeJUnitTestFilterFlags.testFilterForClassesAndMethods(
          failedClassesAndMethods, JUnitVersion.JUNIT_4);
  return filter != null ? BlazeFlags.TEST_FILTER + "=" + filter : null;
}
 
Example #29
Source File: PyTestContextProvider.java    From intellij with Apache License 2.0 5 votes vote down vote up
/**
 * The single selected {@link PsiElement}. Returns null if we're in a SM runner tree UI context
 * (handled by a different producer).
 */
@Nullable
private static PsiElement selectedPsiElement(ConfigurationContext context) {
  List<Location<?>> selectedTestUiElements =
      SmRunnerUtils.getSelectedSmRunnerTreeElements(context);
  if (!selectedTestUiElements.isEmpty()) {
    return null;
  }
  Location<?> location = context.getLocation();
  return location != null ? location.getPsiElement() : null;
}
 
Example #30
Source File: BlazeJUnitTestFilterFlags.java    From intellij with Apache License 2.0 5 votes vote down vote up
/** Only runs specified parameterized versions, where relevant. */
private static List<String> extractMethodFilters(Collection<Location<?>> methods) {
  return methods.stream()
      .map(BlazeJUnitTestFilterFlags::testFilterForLocation)
      .sorted()
      .collect(Collectors.toList());
}