generate method

  1. @override
String generate(
  1. LibraryReader library,
  2. BuildStep buildStep
)

Generates Dart code for an input Dart library.

May create additional outputs through the buildStep, but the 'primary' output is Dart code returned through the Future. If there is nothing to generate for this library may return null, or a Future that resolves to null or the empty string.

Implementation

@override
String generate(LibraryReader library, BuildStep buildStep) {
  final values = <String>{};

  for (final element in library.allElements) {
    // ignore: deprecated_member_use
    if (element is ClassElement && !element.isEnum) {
      for (final field in element.fields) {
        final annotation = getAnnotation(field);
        if (annotation != null) {
          values.add(generateForAnnotatedField(
            field,
            ConstantReader(annotation),
            buildStep,
          ));
        }
      }
    }
  }
  return values.join('\n\n');
}