private static final TreeScanner<Void, Void> createFindIdentifiersScanner(
      ImmutableSet.Builder<Symbol> builder, @Nullable Tree stoppingPoint) {
    return new TreeScanner<Void, Void>() {
      @Override
      public Void scan(Tree tree, Void unused) {
        return Objects.equals(stoppingPoint, tree) ? null : super.scan(tree, unused);
      }

      @Override
      public Void scan(Iterable<? extends Tree> iterable, Void unused) {
        if (stoppingPoint != null && iterable != null) {
          ImmutableList.Builder<Tree> builder = ImmutableList.builder();
          for (Tree t : iterable) {
            if (stoppingPoint.equals(t)) {
              break;
            }
            builder.add(t);
          }
          iterable = builder.build();
        }
        return super.scan(iterable, unused);
      }

      @Override
      public Void visitIdentifier(IdentifierTree identifierTree, Void unused) {
        Symbol symbol = ASTHelpers.getSymbol(identifierTree);
        if (symbol != null) {
          builder.add(symbol);
        }
        return null;
      }
    };
  }
private static final TreeScanner < Void , Void > createFindIdentifiersScanner ( ImmutableSet . Builder < Symbol > builder , @ Nullable Tree stoppingPoint ) { return new TreeScanner < Void , Void > ( ) { @ Override public Void scan ( Tree tree , Void unused ) { return Objects . equals ( stoppingPoint , tree ) ? null : super . scan ( tree , unused ) ; } @ Override public Void scan ( Iterable < ? extends Tree > iterable , Void unused ) { if ( stoppingPoint != null && iterable != null ) { ImmutableList . Builder < Tree > builder = ImmutableList . builder ( ) ; for ( Tree t : iterable ) { if ( stoppingPoint . equals ( t ) ) { break ; } builder . add ( t ) ; } iterable = builder . build ( ) ; } return super . scan ( iterable , unused ) ; } @ Override public Void visitIdentifier ( IdentifierTree identifierTree , Void unused ) { Symbol symbol = ASTHelpers . getSymbol ( identifierTree ) ; if ( symbol != null ) { builder . add ( symbol ) ; } return null ; } } ; }
Finds all identifiers in a tree. Takes an optional stop point as its argument: the depth-first
walk will stop if this node is encountered.