Skip to content

Support FutureOr<String> for Generator{ForAnnotation} #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 0.7.1

### `Generator{ForAnnotation}`

* Return type of `generate{ForAnnotatedElement}` is now `FutureOr<String>`.

### `LibraryReader`

* Added `annotatedElements` to return all elements annotated with something.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> generate(LibraryReader library, BuildStep buildStep) => null;
FutureOr<String> generate(LibraryReader library, BuildStep buildStep) => null;

@override
String toString() => this.runtimeType.toString();
Expand Down
4 changes: 2 additions & 2 deletions lib/src/generator_for_annotation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class GeneratorForAnnotation<T> extends Generator {
@override
Future<String> 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');
Expand All @@ -46,6 +46,6 @@ abstract class GeneratorForAnnotation<T> extends Generator {
///
/// This method is invoked based on finding elements annotated with an
/// instance of [T]. The [annotation] is provided as a [ConstantReader].
Future<String> generateForAnnotatedElement(
FutureOr<String> generateForAnnotatedElement(
Element element, ConstantReader annotation, BuildStep buildStep);
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: source_gen
version: 0.7.0
version: 0.7.1-dev
author: Dart Team <[email protected]>
description: Automated source code generation for Dart.
homepage: https://github.com/dart-lang/source_gen
Expand Down