/** * Resolve the set of all the ancestors declared types of a given type element. * * @param typeElt the type element to resolve * @return the set of ancestors */ public static Set<DeclaredType> resolveAncestorTypes(TypeElement typeElt, boolean withSuper, boolean withInterfaces) { Set<DeclaredType> ancestors = new LinkedHashSet<>(); resolveAncestorTypes(typeElt, ancestors, withSuper, withInterfaces); return ancestors; }
private static void resolveAncestorTypes(TypeElement typeElt, Set<DeclaredType> ancestors, boolean withSuper, boolean withInterfaces) { List<TypeMirror> superTypes = new ArrayList<>(); if (withSuper && typeElt.getSuperclass() != null) { superTypes.add(typeElt.getSuperclass()); } if (withInterfaces) { superTypes.addAll(typeElt.getInterfaces()); } for (TypeMirror superType : superTypes) { if (superType.getKind() == TypeKind.DECLARED) { DeclaredType superDeclaredType = (DeclaredType) superType; if (!ancestors.contains(superDeclaredType)) { ancestors.add(superDeclaredType); resolveAncestorTypes((TypeElement) superDeclaredType.asElement(), ancestors, withSuper, withInterfaces); } } } }
Set<DeclaredType> ancestorTypes = Helper.resolveAncestorTypes(modelElt, true, true); return ancestorTypes. stream().
ownerTypes.add(type); ArrayList<DeclaredType> ancestors = new ArrayList<>(Helper.resolveAncestorTypes(modelElt, true, true));