ServerReflect.fromElement constructor

ServerReflect.fromElement(
  1. Element element
)

Implementation

factory ServerReflect.fromElement(Element element) {
  if (element is! ClassElement) {
    return const ServerReflect.none();
  }

  if (element.library.isInSdk) {
    return const ServerReflect.none();
  }

  final className = element.displayName;

  final metas = <String, List<ServerMimic>>{};

  for (final field in element.fields) {
    getAnnotations(
      element: field,
      onMatch: [
        OnMatch(
          classType: Meta,
          package: 'revali_router_annotations',
          convert: (object, annotation) {
            final meta = ServerMimic.fromDartObject(object, annotation);
            (metas[field.name] ??= []).add(meta);
          },
        ),
      ],
    );
  }

  return ServerReflect(
    className: className,
    metas: metas,
  );
}