code: private static <E extends Element> Set<E> setFilter(Set<? extends Element> elements,
                                                          Set<ElementKind> targetKinds,
                                                          Class<E> clazz) {
          // Return set preserving iteration order of input set.
          Set<E> set = new LinkedHashSet<E>();
          for (Element e : elements) {
              if (targetKinds.contains(e.getKind()))
                  set.add(clazz.cast(e));
          }
          return set;
      }
docs: Assumes targetKinds and E are sensible.