build method

BuildFunctionResult build(
  1. BuildContext context,
  2. Object key,
  3. ({String body, String name, String parameters, String type}) buildBody()
)

Implementation

BuildFunctionResult build(
    BuildContext context,
    Object key,
    ({
      String body,
      String name,
      String parameters,
      String type,
    })
            Function()
        buildBody) {
  final cache = context.initializeCache(
      'parser_builder_lite.parser_builder.function_builder',
      <Object?, BuildFunctionResult>{});
  final found = cache[key];
  if (found != null) {
    return found;
  }

  final body = buildBody();
  final source = render(_template, {
    'body': body.body,
    'name': body.name,
    'parameters': body.parameters,
    'type': body.type,
  });
  final result = BuildFunctionResult(name: body.name, source: source);
  cache[key] = result;
  context.globalOutput.writeln(source);
  return result;
}