@Override
 public ResolvedTargets<Void> findTargetsBeneathDirectory(
     String originalPattern,
     String directory,
     boolean rulesOnly,
     ImmutableSet<String> excludedSubdirectories)
     throws TargetParsingException, InterruptedException {
   FilteringPolicy policy =
       rulesOnly ? FilteringPolicies.RULES_ONLY : FilteringPolicies.NO_FILTER;
   ImmutableSet<PathFragment> excludedPathFragments =
       TargetPatternResolverUtil.getPathFragments(excludedSubdirectories);
   PathFragment pathFragment = TargetPatternResolverUtil.getPathFragment(directory);
   for (Path root : pkgPath.getPathEntries()) {
     RootedPath rootedPath = RootedPath.toRootedPath(root, pathFragment);
     SkyValue token =
         env.getValue(
             PrepareDepsOfTargetsUnderDirectoryValue.key(
                 rootedPath, excludedPathFragments, policy));
     if (token == null) {
       // A null token value means there is a missing dependency, because RecursivePkgFunction
       // never throws.
       throw new MissingDepException();
     }
   }
   return ResolvedTargets.empty();
 }
 static boolean isInternal(RootedPath rootedPath, PathPackageLocator packageLocator) {
   // TODO(bazel-team): This is inefficient when there are a lot of package roots or there are a
   // lot of external directories. Consider either explicitly preventing this case or using a more
   // efficient approach here (e.g. use a trie for determining if a file is under an external
   // directory).
   return packageLocator.getPathEntries().contains(rootedPath.getRoot());
 }