From 0f4eb04dadfd4f933684548284f0785e75c23865 Mon Sep 17 00:00:00 2001 From: David Morgan Date: Tue, 5 Aug 2025 10:48:30 +0200 Subject: [PATCH] Mention directive annotations in CHANGELOG and example. --- example/lib/src/multiplier_generator.dart | 11 +++++++++++ source_gen/CHANGELOG.md | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/example/lib/src/multiplier_generator.dart b/example/lib/src/multiplier_generator.dart index d061e59f..7bc762ea 100644 --- a/example/lib/src/multiplier_generator.dart +++ b/example/lib/src/multiplier_generator.dart @@ -19,4 +19,15 @@ class MultiplierGenerator extends GeneratorForAnnotation { return 'num ${element.name3}Multiplied() => ${element.name3} * $numValue;'; } + + // Override this method to respond to annotations on directives: `import`, + // `export`, `library` and/or `part`. + // + // This generator doesn't respond to such annotations, so do nothing. + @override + dynamic generateForAnnotatedDirective( + ElementDirective directive, + ConstantReader annotation, + BuildStep buildStep, + ); } diff --git a/source_gen/CHANGELOG.md b/source_gen/CHANGELOG.md index b63675c8..7ad0e058 100644 --- a/source_gen/CHANGELOG.md +++ b/source_gen/CHANGELOG.md @@ -4,6 +4,10 @@ do resolution need to switch to the new API, see https://github.com/dart-lang/sdk/blob/main/pkg/analyzer/doc/element_model_migration_guide.md. For questions please use https://github.com/dart-lang/build/discussions. +- **Breaking Change**: annotations are now reported separately for elements + and directives. If you use `TypeChecker().annotatedWith()`, see also + the new `TypeChecker().libraryDirectivesAnnotatedWith()`. If you use + `GeneratorForAnnotation` see the new `generateForAnnotatedDirective`. - Require `build: ^3.0.0` - Updated the minimum package versions for a number of dependencies. - Require Dart 3.7.0