From 01b41985fb02f97dc182a4dff115a0bd5c304c6e Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Thu, 27 Jul 2017 08:11:35 -0700 Subject: [PATCH 1/2] update generate and generateForAnnotation to return a FutureOr instead of a Future --- lib/src/generator.dart | 2 +- lib/src/generator_for_annotation.dart | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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 f0991c59..4014f6a5 100644 --- a/lib/src/generator_for_annotation.dart +++ b/lib/src/generator_for_annotation.dart @@ -39,7 +39,7 @@ abstract class GeneratorForAnnotation extends Generator { var elements = library.allElements .map((e) => new _AnnotatedElement(e, typeChecker.firstAnnotationOf(e))) .where((e) => e.annotation != null); - var allOutput = await Future.wait(elements.map((e) => + var allOutput = await Future.wait(elements.map((e) async => generateForAnnotatedElement( e.element, new ConstantReader(e.annotation), buildStep))); // TODO interleave comments indicating which element produced the output? @@ -50,7 +50,7 @@ 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); } From e6b59b673e49a9026f69837b4ef371f12673a418 Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Thu, 27 Jul 2017 08:14:37 -0700 Subject: [PATCH 2/2] update pubspec/changelog --- CHANGELOG.md | 6 ++++++ pubspec.yaml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca04ebbb..8f3d46cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.7.1-dev + +* Updated return type of `Generator.generate` and + `GeneratorForAnnotation.generateForAnnotatedElement` to `FutureOr` + instead of `Future`. + ## 0.7.0 * **Breaking changes**: See [the wiki](https://github.com/dart-lang/source_gen/wiki/Migrating-to-0.7.x) 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