-
Notifications
You must be signed in to change notification settings - Fork 108
Generate for directive #738
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
947a0e2
0aa4656
2650de3
c6f1dfb
508c6c6
65e26f4
34f9264
f8cac87
8e9138f
72c79d0
98edcac
589ccf5
39075e9
5134899
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
## 2.0.0-wip | ||
## 2.0.0 | ||
|
||
- **DO NOT PUBLISH**: Only land into `analyzer-element2` branch. | ||
When all clients migrate, replace all APIs. | ||
- **Breaking Change**: Change `formatOutput` function to accept a language | ||
version parameter. | ||
- **Formatting Change**: Generated code will no longer apply any fixes by | ||
|
@@ -8,13 +10,17 @@ | |
- Document deduplication behavior for the output of | ||
`GeneratorForAnnotation.generateForAnnotatedElement`. | ||
- Support all the glob quotes. | ||
- Require `analyzer: ^6.9.0` | ||
- Require Dart 3.6.0 | ||
- Require `analyzer: '>=7.2.0 <8.0.0'` | ||
- Support the latest `package:dart_style` | ||
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. We should mention the new API here 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. I wrote something, but I'm not sure if this is exactly what you expected. |
||
- Add `generateForAnnotatedDirective`, which now must be used instead of | ||
`generateForAnnotatedElement` in order to support annotations on directives | ||
(imports, exports, parts). | ||
- `LibraryBuilder`, `PartBuilder`, and `SharedPartBuilder` now take an optional | ||
`writeDescriptions` boolean. When set to `false`, headers and generator | ||
descriptions for the files will not be included in the builder output. | ||
- Include `//dart format width=80` comments in files generated by a | ||
`LibraryBuilder` or `PartBuilder` and formatted with the default callback. | ||
- Require Dart 3.6.0 | ||
|
||
## 1.5.0 | ||
|
||
|
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.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,21 @@ abstract class GeneratorForAnnotation<T> extends Generator { | |
FutureOr<String> generate(LibraryReader library, BuildStep buildStep) async { | ||
final values = <String>{}; | ||
|
||
for (var annotatedDirective in library.libraryDirectivesAnnotatedWith( | ||
typeChecker, | ||
throwOnUnresolved: throwOnUnresolved, | ||
)) { | ||
final generatedValue = generateForAnnotatedDirective( | ||
annotatedDirective.directive, | ||
annotatedDirective.annotation, | ||
buildStep, | ||
); | ||
await for (var value in normalizeGeneratorOutput(generatedValue)) { | ||
assert(value.length == value.trim().length); | ||
values.add(value); | ||
} | ||
} | ||
|
||
for (var annotatedElement in library.annotatedWith( | ||
typeChecker, | ||
throwOnUnresolved: throwOnUnresolved, | ||
|
@@ -123,4 +138,30 @@ abstract class GeneratorForAnnotation<T> extends Generator { | |
ConstantReader annotation, | ||
BuildStep buildStep, | ||
) {} | ||
|
||
/// Implement to return source code to generate for [directive]: | ||
/// - [LibraryImport] | ||
/// - [LibraryExport] | ||
/// - [PartInclude] | ||
/// | ||
/// This method is invoked based on finding directives 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 generateForAnnotatedDirective( | ||
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. What's the deal w/ this @scheglov ? 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. I'm sorry, i don't understand the question. We cannot use the same method for elements and directive. 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. I think we can skip this for now if We will need to be careful not to break internal uses of this and document carefully the impact when we publish externally since this is fairly subtle and it isn't clear in source code exactly when it will matter. |
||
ElementDirective directive, | ||
ConstantReader annotation, | ||
BuildStep buildStep, | ||
) {} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.