ServerMimic.fromDartObject constructor
ServerMimic.fromDartObject(
- DartObject object,
- ElementAnnotation annotation
Implementation
factory ServerMimic.fromDartObject(
DartObject object,
ElementAnnotation annotation,
) {
final objectType = object.type;
final importableElements = <Element?>[objectType?.element];
if (object.type case final InterfaceType type?) {
importableElements.addAll(
type.constructors.map((e) => e.returnType.element),
);
if (type.element case final ClassElement element) {
for (final field in element.fields) {
importableElements.add(field.type.element);
}
}
}
return ServerMimic(
instance: annotation.toSource().replaceFirst('@', ''),
importPaths: ServerImports.fromElements(importableElements),
);
}