build method
Generates the outputs for a given BuildStep
.
Implementation
@override
Future<void> build(BuildStep buildStep) async {
final annotatedElements = await getAnnotatedElements(buildStep);
final allOutputs = <String>[];
for (final annotatedElement in annotatedElements) {
final stopwatch = Stopwatch();
stopwatch.start();
final output = generator.generateAdapter(
annotatedElement.element,
annotatedElement.annotation,
buildStep,
);
// Since the generator must be aware of all classes and LibraryElement only targets
// a single file, this must expand the serialization output into its own file.
final snakedName = StringHelpers.snakeCase(annotatedElement.element.name!);
await manuallyUpsertBrickFile('adapters/${snakedName}_adapter.g.dart', output);
allOutputs.add(output);
logStopwatch(
'Generated ${snakedName}_adapter.g.dart (${annotatedElement.element.name})',
stopwatch,
);
}
await buildStep.writeAsString(
buildStep.inputId.changeExtension(outputExtension),
allOutputs.join('\n'),
);
}