generate method
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
Future<String> generate(LibraryReader library, BuildStep buildStep) async {
final result = StringBuffer();
var hasWrittenHeaders = false;
final nndbEnabled = await buildStep.inputLibrary
.then((value) => value.featureSet.isEnabled(Feature.non_nullable));
for (final element in library.allElements) {
if (_isReduxActions(element) && element is ClassElement) {
if (!hasWrittenHeaders) {
hasWrittenHeaders = true;
result.writeln(_lintIgnores);
}
log.info('Generating action classes for ${element.name}');
result.writeln(_generateActions(element, nndbEnabled));
}
}
return result.toString();
}