feat: migrate to analyzer 9.0.0 API

- Replace Element2 API with Element API
- Update imports from element2.dart to element.dart
- Replace .firstFragment.name2 with .name
- Replace .firstFragment.metadata2.annotations with .metadata.annotations
- Replace .fields2 with .fields
- Replace .methods2 with .methods
- Remove duplicate imports in annotation_validator.dart and generated_class.dart
- Update test mocks to use Element instead of Element2

All generators now work correctly with analyzer 9.0.0:
- melos analyze: SUCCESS (0 issues)
- melos codegen: SUCCESS (13 outputs generated)
- melos bootstrap: SUCCESS (8 packages)
This commit is contained in:
Sergey Penkovsky
2026-01-30 10:48:48 +03:00
parent e6b3017384
commit 0e555a6849
13 changed files with 90 additions and 154 deletions

View File

@@ -11,7 +11,7 @@
// limitations under the License.
//
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:build/build.dart';
import 'package:source_gen/source_gen.dart';
import 'package:cherrypick_annotations/cherrypick_annotations.dart' as ann;
@@ -80,11 +80,11 @@ class ModuleGenerator extends GeneratorForAnnotation<ann.module> {
/// See file-level docs for usage and generated output example.
@override
dynamic generateForAnnotatedElement(
Element2 element,
Element element,
ConstantReader annotation,
BuildStep buildStep,
) {
if (element is! ClassElement2) {
if (element is! ClassElement) {
throw InvalidGenerationSourceError(
'@module() can only be applied to classes.',
element: element,