from method

Iterable<FunctionMirror>? from(
  1. dynamic instance
)

Get List of methods annotated with T. For example:

class ObjectWithAnnotatedAttr {

  @Annotation1()
  @Annotation2()
  var annotated1

  @Annotation1()
  var annotated2
}

main() {
  var o = new ObjectWithAnnotatedAttr();

  //should return a list of [DeclarationMirror] of annotated1 and annotated2
  var methodsAnnotatedWithAnnotation1 = new GetMethodsAnnotatedWith<Annotation1>().from(o);

  //should return a list of [DeclarationMirror] of annotated1
  var methodsAnnotatedWithAnnotation2 = new GetMethodsAnnotatedWith<Annotation2>().from(o);

Implementation

Iterable<FunctionMirror>? from(instance) => reflect(instance)
    ?.methods
    ?.values
    .where((methodMirror) => methodMirror.annotations?.any((a) => a is T) == true);