From 7570742f0c2bbf3ad2e712ed6b0943ed32b6b4cd Mon Sep 17 00:00:00 2001 From: Gabriel Gava Date: Thu, 28 Aug 2025 15:06:38 +0200 Subject: [PATCH] Updates to analyzer ^7.4.0 - Analyzer 6 depends on _macros which was removed from latest dart (3.9.0) of flutter stable So support to analyzer 7 onwards is needed to be able to update to latest flutter - Also drops supports to all other versions prior to 7 since none of them compiles with current code (analyzer has a very unstable interface) --- .gitignore | 5 +++- functional_data_generator/lib/builder.dart | 29 +++++++++++----------- functional_data_generator/pubspec.yaml | 10 ++++---- pubspec.yaml | 4 +-- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 4145a0f..a9e3784 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,7 @@ .pub/ build/ -pubspec_overrides.yaml \ No newline at end of file +pubspec_overrides.yaml + +# ASDF +.tool-versions \ No newline at end of file diff --git a/functional_data_generator/lib/builder.dart b/functional_data_generator/lib/builder.dart index f5969cc..37a59ed 100644 --- a/functional_data_generator/lib/builder.dart +++ b/functional_data_generator/lib/builder.dart @@ -1,7 +1,7 @@ import 'dart:io'; import 'package:analyzer/dart/ast/ast.dart'; -import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:build/build.dart'; import 'package:collection/collection.dart'; import 'package:functional_data/functional_data.dart'; @@ -12,13 +12,13 @@ Builder functionalData(BuilderOptions options) => SharedPartBuilder([FunctionalD class FunctionalDataGenerator extends GeneratorForAnnotation { @override - Future generateForAnnotatedElement(Element element, ConstantReader annotation, BuildStep buildStep) => + Future generateForAnnotatedElement(Element2 element, ConstantReader annotation, BuildStep buildStep) => _generateDataType(element, annotation, buildStep); } String? _getCustomEquality(List annotations) { - final annotation = annotations.firstWhereOrNull( - (a) => a.computeConstantValue()?.type?.getDisplayString(withNullability: false) == 'CustomEquality'); + final annotation = + annotations.firstWhereOrNull((a) => a.computeConstantValue()?.type?.getDisplayString() == 'CustomEquality'); if (annotation != null) { final source = annotation.toSource(); final customEquality = source.substring('@CustomEquality('.length, source.length - 1).replaceAll('?', ''); @@ -39,8 +39,8 @@ class Pair { final S second; } -Future _generateDataType(Element element, ConstantReader annotation, BuildStep buildStep) async { - if (element is! ClassElement) { +Future _generateDataType(Element2 element, ConstantReader annotation, BuildStep buildStep) async { + if (element is! ClassElement2) { throw Exception('FunctionalData annotation must only be used on classes'); } @@ -63,25 +63,26 @@ Future _generateDataType(Element element, ConstantReader annotation, Bui throw Exception('[$element]: generateLenses requires copyWith to be generated'); } - final className = element.name.replaceAll('\$', ''); + final className = (element.name3 ?? '').replaceAll('\$', ''); final classElement = element; // The one that can be used to specify every field - final genericConstructor = classElement.constructors.firstWhere((element) => element.name.isEmpty); - final positionalFields = genericConstructor.parameters.where((p) => p.isPositional).map((p) => p.name).toList(); + final genericConstructor = classElement.constructors2.firstWhere((element) => element.name3 == 'new'); + final positionalFields = + genericConstructor.formalParameters.where((p) => p.isPositional).map((p) => p.name3).toList(); final fieldsWithIndex = - await Future.wait(classElement.fields.where((f) => !f.isSynthetic && !f.isStatic).map((f) async { - final declaration = await buildStep.resolver.astNodeFor(f) as VariableDeclaration?; + await Future.wait(classElement.fields2.where((f) => !f.isSynthetic && !f.isStatic).map((f) async { + final declaration = await buildStep.resolver.astNodeFor(f.firstFragment) as VariableDeclaration?; final declarationList = declaration?.parent as VariableDeclarationList?; - final positionalIndex = positionalFields.indexOf(f.name); + final positionalIndex = positionalFields.indexOf(f.name3); return Pair( positionalIndex == -1 ? 9999 : positionalIndex, Field( - f.name, + f.name3 ?? '', declarationList?.type?.toSource() ?? 'dynamic', - _getCustomEquality(f.metadata), + _getCustomEquality(f.metadata2.annotations), isPositional: positionalIndex != -1, ), ); diff --git a/functional_data_generator/pubspec.yaml b/functional_data_generator/pubspec.yaml index 9826569..7488641 100644 --- a/functional_data_generator/pubspec.yaml +++ b/functional_data_generator/pubspec.yaml @@ -8,13 +8,13 @@ environment: sdk: '>=2.19.0 <4.0.0' dependencies: - analyzer: '>=2.0.0 <7.0.0' - build: ^2.0.1 + analyzer: '^7.4.0' + build: ^3.0.0 collection: ^1.15.0 functional_data: ^1.1.1 - source_gen: ^1.2.7 + source_gen: ^3.1.0 yaml: ^3.1.2 dev_dependencies: - build_resolvers: "^2.0.2" - build_runner: ^2.2.0 + build_resolvers: "^3.0.2" + build_runner: ^2.2.0 \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 2fff3e5..6ad0316 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: functional_data_workspace environment: - sdk: '>=2.19.0 <3.0.0' + sdk: '>=2.19.0 <4.0.0' dev_dependencies: - melos: ^5.3.0 + melos: ^6.3.0