google / reflectable.dart

Reflectable is a Dart library that allows programmers to eliminate certain usages of dynamic reflection by specialization of reflective code to an equivalent implementation using only static techniques. The use of dynamic reflection is constrained in order to ensure that the specialized code can be generated and will have a reasonable size.
https://pub.dev/packages/reflectable
BSD 3-Clause "New" or "Revised" License
381 stars 57 forks source link

Annotated parameter and Functions #317

Open cheogm28 opened 1 year ago

cheogm28 commented 1 year ago

Sorry If this is an open issue or if there is dcumentation about I tried to figure this out but I could not find the soulution. I have a class that has anotations on the methods is it posible to get the metadata of the class and then go throug the methods and check if the method is of type annotation . For instance :

@annotationA
class A {
   @method
   A getA(){
      return A();
   }
}

I did it with mirrors using the "is subtype of " after extracting the metadata and compering it with the Type. But now if I try something similar it returns false . What I am doing in the reflect part is calling a method that checks if the method has anotations

var rootMember = A.reflectType(classA) as ClassMirror;

  ....
  rootMember.metadata.where((element) => isAnnotatedMethod(element));

  ....
bool isAnnotatedMethod(element) {
 A.canReflect(element);
}