getAnnotationsFromField method

Future<List<Annotation>> getAnnotationsFromField(
  1. Type _type,
  2. String propertyName
)

Implementation

Future<List<Annotation>> getAnnotationsFromField(
    Type _type, String propertyName) async {
  var type = reflectClass(_type);
  var field = (await getClassDeclarationFromType(type.reflectedType))
      ?.getField(propertyName);
  while (field == null) {
    type = type.superclass!;
    if (type.reflectedType == Object) {
      break;
    }
    field = (await getClassDeclarationFromType(type.reflectedType))
        ?.getField(propertyName);
  }

  if (field == null) {
    return [];
  }

  return (field.parent!.parent! as FieldDeclaration).metadata.toList();
}