getDirectAnnotations<A> method

Iterable<A> getDirectAnnotations<A>()

Gets all annotations of a specific type.

Type Parameters:

  • A: The annotation type to filter for

Returns:

  • A list of all matching annotation instances
  • Empty list if none found

Note: Useful for repeatable annotations that may appear multiple times.

Example:

final routes = method.getDirectAnnotations<Route>();
for (final route in routes) {
  print('Route path: ${route.path}');
}

Implementation

Iterable<A> getDirectAnnotations<A>() {
  checkAccess('getDirectAnnotations', DomainPermission.READ_ANNOTATIONS);
  final annotations = getAllDirectAnnotations();
  final result = <A>[];
  for (final annotation in annotations) {
    if (annotation.matches<A>()) {
      try {
        final inst = annotation.getInstance<A>();
        if (inst != null) result.add(inst);
      } catch (_) {}
    }
  }
  return UnmodifiableListView(result);
}