Java Code Examples for com.intellij.openapi.roots.ProjectFileIndex#isInTestSourceContent()

The following examples show how to use com.intellij.openapi.roots.ProjectFileIndex#isInTestSourceContent() . 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: MultipleJavaClassesTestContextProvider.java    From intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a {@link RunConfigurationContext} future setting up the relevant test target pattern,
 * if one can be found.
 */
@Nullable
private static ListenableFuture<TargetInfo> getTargetContext(PsiDirectory dir) {
  Project project = dir.getProject();
  ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(project);
  if (!index.isInTestSourceContent(dir.getVirtualFile())) {
    return null;
  }
  if (BlazePackage.isBlazePackage(dir)) {
    // this case is handled by a separate run config producer
    return null;
  }
  ListenableFuture<Set<PsiClass>> classes = findAllTestClassesBeneathDirectory(dir);
  if (classes == null) {
    return null;
  }
  return Futures.transformAsync(
      classes,
      set -> set == null ? null : ReadAction.compute(() -> getTestTargetIfUnique(project, set)),
      EXECUTOR);
}
 
Example 2
Source File: SimpleCoverageAnnotator.java    From consulo with Apache License 2.0 6 votes vote down vote up
@javax.annotation.Nullable
protected DirCoverageInfo getDirCoverageInfo(@Nonnull final PsiDirectory directory,
                                             @Nonnull final CoverageSuitesBundle currentSuite) {
  final VirtualFile dir = directory.getVirtualFile();

  final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(directory.getProject()).getFileIndex();
  //final Module module = projectFileIndex.getModuleForFile(dir);

  final boolean isInTestContent = projectFileIndex.isInTestSourceContent(dir);
  if (!currentSuite.isTrackTestFolders() && isInTestContent) {
    return null;
  }

  final String path = normalizeFilePath(dir.getPath());

  return isInTestContent ? myTestDirCoverageInfos.get(path) : myDirCoverageInfos.get(path);
}
 
Example 3
Source File: ProjectProductionScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ProjectProductionScope() {
  super(IdeBundle.message("predefined.scope.production.name"), new AbstractPackageSet("project:*..*") {
    @Override
    public boolean contains(VirtualFile file, NamedScopesHolder holder) {
      final ProjectFileIndex index = ProjectRootManager.getInstance(holder.getProject()).getFileIndex();
      return file != null
             && !index.isInTestSourceContent(file)
             && !index.isInLibraryClasses(file)
             && !index.isInLibrarySource(file);
    }
  });
}
 
Example 4
Source File: CppSupportLoader.java    From CppTools with Apache License 2.0 5 votes vote down vote up
public static boolean isInSource(VirtualFile virtualFile, ProjectFileIndex fileIndex) {
  if (fileIndex.isInSourceContent(virtualFile)) {
    return !fileIndex.isInTestSourceContent(virtualFile) &&
      fileIndex.getModuleForFile(virtualFile) != null;
  } else if (!EnvironmentFacade.isJavaIde()) {
    return fileIndex.getModuleForFile(virtualFile) != null;
  }
  return false;
}