parseDocComponent function

DocComponent parseDocComponent(
  1. MethodInvocation docExpr
)

Parse a DocComponent from a MethodInvocation AST node.

Implementation

DocComponent parseDocComponent(MethodInvocation docExpr) {
  // Extract the component data
  final name = docExpr.get<String>('name');
  final isNullSafe = docExpr.get<bool?>('isNullSafe') ?? false;
  final description = docExpr.get<String>('description');
  final methods = docExpr.get<List<String>>('methods');

  // Parse constructors
  final constructors = <DocConstructor>[];
  final constructorsArg = docExpr.get<ListLiteral>('constructors');
  for (final constrExpr in constructorsArg.elements) {
    final signature = <DocParameter>[];
    final params = constrExpr.get<ListLiteral?>('signature');
    for (CollectionElement param in params?.elements ?? []) {
      signature.add(DocParameter(
        name: param.get<String>('name'),
        type: param.get<String>('type'),
        description: param.get<String>('description'),
        named: param.get<bool?>('named') ?? false,
        required: param.get<bool?>('required') ?? false,
      ));
    }
    constructors.add(DocConstructor(
      name: constrExpr.get<String>('name'),
      signature: signature,
      features: [],
    ));
  }

  // Parse properties
  final properties = <DocProperty>[];
  final propertiesArg = docExpr.get<ListLiteral>('properties');
  for (final propExpr in propertiesArg.elements) {
    properties.add(DocProperty(
      name: propExpr.get<String>('name'),
      type: propExpr.get<String>('type'),
      description: propExpr.get<String>('description'),
      features: propExpr.get<List<String>>('features'),
    ));
  }

  return DocComponent(
    name: name,
    isNullSafe: isNullSafe,
    description: description,
    constructors: constructors,
    properties: properties,
    methods: methods,
  );
}