ServerBindsAnnotation.fromElement constructor
ServerBindsAnnotation.fromElement(
- DartObject object,
- ElementAnnotation annotation
Implementation
factory ServerBindsAnnotation.fromElement(
DartObject object,
// ignore: avoid_unused_constructor_parameters
ElementAnnotation annotation,
) {
final bind = object.getField('bind')?.toTypeValue();
if (bind == null) {
throw ArgumentError('Invalid type');
}
final bindSuper = (bind.element as ClassElement?)?.allSupertypes
.firstWhereOrNull((element) {
return element.element.name == (Bind).name;
});
if (bindSuper == null) {
throw ArgumentError('Failed to find superclass of $bind');
}
final [typeArg] = bindSuper.typeArguments;
return ServerBindsAnnotation(
bind: ServerBind.fromType(bind),
convertsTo: ServerType.fromType(typeArg),
);
}