code: private static <D extends Directive> List<D> listFilter(Iterable<? extends Directive> directives,
                                                            DirectiveKind directiveKind,
                                                            Class<D> clazz) {
          List<D> list = new ArrayList<>();
          for (Directive d : directives) {
              if (d.getKind() == directiveKind)
                  list.add(clazz.cast(d));
          }
          return list;
      }
docs: Assumes directiveKind and D are sensible.