AnnotationArguments.fromDartObject constructor

AnnotationArguments.fromDartObject(
  1. ElementAnnotation annotation
)

Implementation

factory AnnotationArguments.fromDartObject(ElementAnnotation annotation) {
  final positionalArguments = <AnnotationArgument>[];
  final namedArguments = <String, AnnotationArgument>{};

  if (annotation case ElementAnnotationImpl(
    annotationAst: Annotation(
      arguments: ArgumentList(childEntities: final args),
    ),
  )) {
    for (final param in args) {
      if (param case NamedExpression(:final name, :final expression)) {
        namedArguments[name.label.name] = AnnotationArgument.fromExpression(
          expression,
        );
      } else if (param case final Expression expression) {
        positionalArguments.add(
          AnnotationArgument.fromExpression(expression),
        );
      }
    }
  }

  return AnnotationArguments(
    positional: positionalArguments,
    named: namedArguments,
  );
}