@Test public void shouldGetParents() throws Exception { TypeElement twiceNested = compilation.getElements() .getTypeElement(Outer.Nested.TwiceNested.class.getCanonicalName()); List<? extends Element> members = compilation.getElements().getAllMembers(twiceNested); Element field = members.stream().filter(ofKind(ElementKind.FIELD)).findFirst() .orElseThrow(IllegalStateException::new); List<String> parents = stream(field) .map(element -> element.getSimpleName().toString()) .collect(Collectors.toList()); assertThat(parents, hasItems("field", "TwiceNested", "Nested", "Outer")); }
public static Stream<Element> stream(Element element) { return StreamSupport.stream(new ElementParentsIterable(element).spliterator(), false); }
ElementParentsIterable implements Iterable<Element> { public static Stream<Element> stream(Element element) { return StreamSupport.stream(new ElementParentsIterable(element).spliterator(), false); } }
ElementParentsIterable implements Iterable<Element> { public static Stream<Element> stream(Element element) { return StreamSupport.stream(new ElementParentsIterable(element).spliterator(), false); } ElementParentsIterable(Element start); }
ElementParentsIterable implements Iterable<Element> { public static Stream<Element> stream(Element element) { return StreamSupport.stream(new ElementParentsIterable(element).spliterator(), false); } ElementParentsIterable(Element start); @Override Iterator<Element> iterator(); static Stream<Element> stream(Element element); }
ElementParentsIterable implements Iterable<Element> { public static Stream<Element> stream(Element element) { return StreamSupport.stream(new ElementParentsIterable(element).spliterator(), false); } ElementParentsIterable(Element start); @Override Iterator<Element> iterator(); static Stream<Element> stream(Element element);  }