diff --git a/CHANGELOG.md b/CHANGELOG.md index 80bd92ed..15302e0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## 0.7.1 +### `Generator{ForAnnotation}` + +* Return type of `generate{ForAnnotatedElement}` is now `FutureOr`. + ### `LibraryReader` * Added `annotatedElements` to return all elements annotated with something. diff --git a/lib/src/generator.dart b/lib/src/generator.dart index 84636e62..923da228 100644 --- a/lib/src/generator.dart +++ b/lib/src/generator.dart @@ -20,7 +20,7 @@ abstract class Generator { /// 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. - Future generate(LibraryReader library, BuildStep buildStep) => null; + FutureOr generate(LibraryReader library, BuildStep buildStep) => null; @override String toString() => this.runtimeType.toString(); diff --git a/lib/src/generator_for_annotation.dart b/lib/src/generator_for_annotation.dart index 46b76071..c4dc0ace 100644 --- a/lib/src/generator_for_annotation.dart +++ b/lib/src/generator_for_annotation.dart @@ -36,7 +36,7 @@ abstract class GeneratorForAnnotation extends Generator { @override Future generate(LibraryReader library, BuildStep buildStep) async { var elements = library.annotatedWith(typeChecker); - var allOutput = await Future.wait(elements.map((e) => + var allOutput = await Future.wait(elements.map((e) async => generateForAnnotatedElement(e.element, e.annotation, buildStep))); // TODO interleave comments indicating which element produced the output? return allOutput.join('\n'); @@ -46,6 +46,6 @@ abstract class GeneratorForAnnotation extends Generator { /// /// This method is invoked based on finding elements annotated with an /// instance of [T]. The [annotation] is provided as a [ConstantReader]. - Future generateForAnnotatedElement( + FutureOr generateForAnnotatedElement( Element element, ConstantReader annotation, BuildStep buildStep); } diff --git a/pubspec.yaml b/pubspec.yaml index 3359f685..6e93eec9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: source_gen -version: 0.7.0 +version: 0.7.1-dev author: Dart Team description: Automated source code generation for Dart. homepage: https://github.com/dart-lang/source_gen