-
Notifications
You must be signed in to change notification settings - Fork 111
Add APIs to expose analyzer elements2 models. #735
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import 'dart:async'; | ||
|
||
import 'package:analyzer/dart/element/element.dart'; | ||
import 'package:analyzer/dart/element/element2.dart'; | ||
import 'package:build/build.dart'; | ||
|
||
import 'constants/reader.dart'; | ||
|
@@ -58,11 +59,16 @@ abstract class GeneratorForAnnotation<T> extends Generator { | |
typeChecker, | ||
throwOnUnresolved: throwOnUnresolved, | ||
)) { | ||
final generatedValue = generateForAnnotatedElement( | ||
var generatedValue = generateForAnnotatedElement( | ||
annotatedElement.element, | ||
annotatedElement.annotation, | ||
buildStep, | ||
); | ||
generatedValue ??= generateForAnnotatedElement2( | ||
annotatedElement.element2, | ||
annotatedElement.annotation, | ||
buildStep, | ||
); | ||
await for (var value in normalizeGeneratorOutput(generatedValue)) { | ||
assert(value.length == value.trim().length); | ||
values.add(value); | ||
|
@@ -93,5 +99,28 @@ abstract class GeneratorForAnnotation<T> extends Generator { | |
Element element, | ||
ConstantReader annotation, | ||
BuildStep buildStep, | ||
); | ||
) {} | ||
|
||
/// Implement to return source code to generate for [element]. | ||
/// | ||
/// This method is invoked based on finding elements annotated with an | ||
/// instance of [T]. The [annotation] is provided as a [ConstantReader]. | ||
/// | ||
/// Supported return values include a single [String] or multiple [String] | ||
/// instances within an [Iterable] or [Stream]. It is also valid to return a | ||
/// [Future] of [String], [Iterable], or [Stream]. When multiple values are | ||
/// returned through an iterable or stream they will be deduplicated. | ||
/// Typically each value will be an independent unit of code and the | ||
/// deduplication prevents re-defining the same member multiple times. For | ||
/// example if multiple annotated elements may need a specific utility method | ||
/// available it can be output for each one, and the single deduplicated | ||
/// definition can be shared. | ||
/// | ||
/// Implementations should return `null` when no content is generated. Empty | ||
/// or whitespace-only [String] instances are also ignored. | ||
dynamic generateForAnnotatedElement2( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, so which version is going to be called? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both, but any specific generator will override only one. |
||
Element2 element, | ||
ConstantReader annotation, | ||
BuildStep buildStep, | ||
) {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a changelog update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will never be published, we will restore the name with different types.