rulebook-core/src/main/java/com/deliveredtechnologies/rulebook/util/AnnotationUtils.java
@SuppressWarnings("unchecked")
  public static List<Field> getAnnotatedFields(Class annotation, Class clazz) {
    if (clazz == Object.class) {
      return new ArrayList<>();
    }
    List<Field> fields = (List<Field>)Arrays.stream(clazz.getDeclaredFields())
            .filter(field -> field.getAnnotation(annotation) != null)
            .collect(Collectors.toList());
    if (clazz.getSuperclass() != null) {
      fields.addAll(getAnnotatedFields(annotation, clazz.getSuperclass()));
    }
    return fields;
  }
@SuppressWarnings("unchecked")
  public static List<Field> getAnnotatedFields(Class annotation, Class clazz) {
    if (clazz == Object.class) {
      return new ArrayList<>();
    }
    List<Field> fields = (List<Field>)Arrays.stream(clazz.getDeclaredFields())
            .filter(field -> field.getAnnotation(annotation) != null)
            .collect(Collectors.toList());
    if (clazz.getSuperclass() != null) {
      fields.addAll(getAnnotatedFields(annotation, clazz.getSuperclass()));
    }
    return fields;
  }
@ SuppressWarnings ( "unchecked" ) public static List < Field > getAnnotatedFields ( Class annotation , Class clazz ) { if ( clazz == Object . class ) { return new ArrayList <> ( ) ; } List < Field > fields = ( List < Field > ) Arrays . stream ( clazz . getDeclaredFields ( ) ) . filter ( field -> field . getAnnotation ( annotation ) != null ) . collect ( Collectors . toList ( ) ) ; if ( clazz . getSuperclass ( ) != null ) { fields . addAll ( getAnnotatedFields ( annotation , clazz . getSuperclass ( ) ) ) ; } return fields ; }
Method getAnnotatedFields gets the fields annotated of a specific type from the class and its parent classes. <br/>
The List is in order of closest parent => current obj fields, parent obj fields, etc.
@param annotation      the annotation type
@param clazz           the class that is expected to be annotated
@return                a {@link Set} of {@link Field} objects annotated with the annotatedClass
Method getAnnotatedFields gets the fields annotated of a specific type from the class and its parent classes . <br / > The List is in order of closest parent = > current obj fields parent obj fields etc .