ServerLifecycleComponent.fromDartObject constructor

ServerLifecycleComponent.fromDartObject(
  1. DartObject object,
  2. ElementAnnotation annotation
)

Implementation

factory ServerLifecycleComponent.fromDartObject(
  DartObject object,
  ElementAnnotation annotation,
) {
  if (object.type case final InterfaceType type) {
    final element = type.element;
    if (element is! ClassElement) {
      throw Exception('Invalid element type');
    }

    final arguments = AnnotationArguments.fromDartObject(annotation);
    final constructor =
        object.constructorInvocation?.constructor ??
        element.constructors.firstWhereOrNull((e) => e.isPublic);

    return ServerLifecycleComponent.fromClassElement(
      element,
      arguments,
      constructor: constructor,
      instanceFields: object,
    );
  }

  throw Exception('Expected annotation type to be InterfaceType');
}