getAttachments function

String? getAttachments(
  1. Element element
)

Implementation

String? getAttachments(Element element) {
  // final annotDefault = const TypeChecker.fromRuntime(Attach)
  //     .annotationsOf(element).expand((e) => e.toListValue()?.map((e) => e.));
  String fieldAnnotations = '';
  if (element is ParameterElement &&
      element.enclosingElement is ConstructorElement) {
    final constructor = element.enclosingElement! as ConstructorElement;
    final field = constructor.enclosingElement.getField(element.name);
    if (field != null && field.type.element == element.type.element) {
      fieldAnnotations = getAttachments(field) ?? '';
      if (fieldAnnotations.isNotEmpty) {
        fieldAnnotations = fieldAnnotations.substring(
          1,
          fieldAnnotations.length - 1,
        );
      }
    }
  }
// ignore: prefer_interpolation_to_compose_strings
  final str = '[' +
      const TypeChecker.fromRuntime(AttachFn)
          .annotationsOf(element)
          .map((e) {
            final fun = e.getField('attachments')?.toFunctionValue();
            return fun == null ? null : executeCodeForExecutable(fun);
          })
          .whereType<String>()
          .map((e) => '...$e,')
          .join() +
      (() {
        // TODO: 1G ValidaNested.overrideValidation
        final e = element.metadata.firstWhereOrNull(
          (element) => const TypeChecker.fromRuntime(ValidaField)
              .isAssignableFromType(element.computeConstantValue()!.type!),
        );
        if (e == null) return '';
        final _validaAnnot = getSourceCodeAnnotation(e);
        return 'ValidaAttachment($_validaAnnot),';
      }()) +
      fieldAnnotations +
      ']';
  return str.length > 2 ? str : null;
}