private static PsiDirectory[] filterSourceDirectories(
     PsiDirectory baseDir, Project project, PsiDirectory[] moduleDirectories) {
   final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
   if (fileIndex.isInTestSourceContent(baseDir.getVirtualFile())) {
     List<PsiDirectory> result = new ArrayList<PsiDirectory>();
     for (PsiDirectory moduleDirectory : moduleDirectories) {
       if (fileIndex.isInTestSourceContent(moduleDirectory.getVirtualFile())) {
         result.add(moduleDirectory);
       }
     }
     moduleDirectories = result.toArray(new PsiDirectory[result.size()]);
   }
   return moduleDirectories;
 }
  @Override
  @Nullable
  public GlobalSearchScope getSearchScope() {
    GlobalSearchScope scope = null;

    Module[] modules = getConvertContextModules();
    if (modules.length != 0) {

      PsiFile file = getFile();
      file = file.getOriginalFile();
      VirtualFile virtualFile = file.getVirtualFile();
      if (virtualFile != null) {
        ProjectFileIndex fileIndex =
            ProjectRootManager.getInstance(file.getProject()).getFileIndex();
        boolean tests = fileIndex.isInTestSourceContent(virtualFile);

        for (Module module : modules) {
          if (scope == null) {
            scope = module.getModuleRuntimeScope(tests);
          } else {
            scope = scope.union(module.getModuleRuntimeScope(tests));
          }
        }
      }
    }
    return scope; // ??? scope == null ? GlobalSearchScope.allScope(getProject()) : scope; ???
  }
 public static boolean isTest(VirtualFile virtualFile, Project project) {
   if (virtualFile == null) {
     return false;
   }
   final ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
   final ProjectFileIndex fileIndex = rootManager.getFileIndex();
   return fileIndex.isInTestSourceContent(virtualFile);
 }
  public void markModuleDirtyIfInSourceRoot(final VirtualFile file) {
    if (myCache.isEmpty()) return;

    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
    final Module module = fileIndex.getModuleForFile(file);
    if (module != null
        && fileIndex.getSourceRootForFile(file) != null
        && !fileIndex.isInTestSourceContent(file)) {
      markModuleDirty(module);
    }
  }
 @Override
 public boolean isInTestSourceContent(@NotNull final VirtualFile fileOrDir) {
   if (myProjectFileIndex.isInTestSourceContent(fileOrDir)
       || myProjectFileIndex.isInTestResource(fileOrDir)) {
     return true;
   }
   if (isUnderRoots(myGeneratedTestRoots, fileOrDir)) {
     return true;
   }
   return false;
 }
  private void updateErrorMessage(
      Pass<String> updateErrorMessage, ProjectFileIndex fileIndex, Object selectedItem) {
    updateErrorMessage.pass(null);
    if (myInitialTargetDirectory != null
        && selectedItem instanceof DirectoryChooser.ItemWrapper
        && selectedItem != NULL_WRAPPER) {
      final PsiDirectory directory = ((DirectoryChooser.ItemWrapper) selectedItem).getDirectory();
      final boolean isSelectionInTestSourceContent =
          fileIndex.isInTestSourceContent(directory.getVirtualFile());
      final boolean inTestSourceContent =
          fileIndex.isInTestSourceContent(myInitialTargetDirectory.getVirtualFile());
      if (isSelectionInTestSourceContent != inTestSourceContent) {
        if (inTestSourceContent && reportBaseInTestSelectionInSource()) {
          updateErrorMessage.pass("Source root is selected while the test root is expected");
        }

        if (isSelectionInTestSourceContent && reportBaseInSourceSelectionInTest()) {
          updateErrorMessage.pass("Test root is selected while the source root is expected");
        }
      }
    }
  }
 protected boolean isTestScope(@Nullable final PsiFile context) {
   if ((context == null)) {
     return false;
   }
   PsiFile _originalFile = context.getOriginalFile();
   VirtualFile virtualFile = _originalFile.getVirtualFile();
   if ((virtualFile != null)) {
     Project _project = context.getProject();
     ProjectRootManager _instance = ProjectRootManager.getInstance(_project);
     ProjectFileIndex _fileIndex = _instance.getFileIndex();
     return _fileIndex.isInTestSourceContent(virtualFile);
   }
   return false;
 }
 @Nullable
 private static DirectoryChooser.ItemWrapper chooseSelection(
     final VirtualFile initialTargetDirectorySourceRoot,
     final ProjectFileIndex fileIndex,
     final ArrayList<DirectoryChooser.ItemWrapper> items,
     final DirectoryChooser.ItemWrapper initial,
     final DirectoryChooser.ItemWrapper oldOne) {
   if (initial != null || items.contains(NULL_WRAPPER) || items.isEmpty()) {
     return initial;
   } else {
     if (oldOne != null) {
       return oldOne;
     } else if (initialTargetDirectorySourceRoot != null) {
       final boolean inTest = fileIndex.isInTestSourceContent(initialTargetDirectorySourceRoot);
       for (DirectoryChooser.ItemWrapper item : items) {
         final VirtualFile virtualFile = item.getDirectory().getVirtualFile();
         if (fileIndex.isInTestSourceContent(virtualFile) == inTest) {
           return item;
         }
       }
     }
   }
   return items.get(0);
 }