private static boolean processChildren(PsiDirectory directory, @Nullable Object rootElement, Processor<Object> processor) {
    return ReadAction.compute(() -> {
      Project project = directory.getProject();
      RootType scratchRootType = RootType.forFile(PsiUtilCore.getVirtualFile(directory));
      ModuleFileIndex moduleFileIndex =
        rootElement instanceof Module ? ModuleRootManager.getInstance((Module)rootElement).getFileIndex() : null;
      return directory.processChildren(child -> {
        VirtualFile childFile = PsiUtilCore.getVirtualFile(child);
        if (childFile != null && scratchRootType != null && scratchRootType.isIgnored(project, childFile)) return true;
        if (childFile != null && moduleFileIndex != null && !moduleFileIndex.isInContent(childFile)) return true;
        return processor.process(child);
      });
    });
  }
private static boolean processChildren(PsiDirectory directory, @Nullable Object rootElement, Processor<Object> processor)