diff --git a/packages/reflectable/CHANGELOG.md b/packages/reflectable/CHANGELOG.md index 55b19086..7b83f0b7 100644 --- a/packages/reflectable/CHANGELOG.md +++ b/packages/reflectable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.2.0 + +- Upgrade reflectable to use analyzer ^10.0.0 and lints ^6.0.0. + ## 5.1.0 - Upgrade reflectable to use version ^8.0.0 of the analyzer and version diff --git a/packages/reflectable/pubspec.yaml b/packages/reflectable/pubspec.yaml index 33d1c832..321c7360 100644 --- a/packages/reflectable/pubspec.yaml +++ b/packages/reflectable/pubspec.yaml @@ -1,5 +1,5 @@ name: reflectable -version: 5.1.0 +version: 5.2.0 description: > Reflection support based on code generation, using 'capabilities' to specify which operations to support, on which objects. This is the @@ -10,4 +10,4 @@ environment: resolution: workspace dependencies: dev_dependencies: - lints: ^5.0.0 + lints: ^6.0.0 diff --git a/packages/reflectable_builder/CHANGELOG.md b/packages/reflectable_builder/CHANGELOG.md index 8d41e80f..d96c7b7c 100644 --- a/packages/reflectable_builder/CHANGELOG.md +++ b/packages/reflectable_builder/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.2.0 + +- Upgrade the code generator to use analyzer ^10.0.0 and lints 6.0.0. + Remove dependencies on discontinued packages. + ## 1.1.0 - Upgrade the reflectable code generator to use version ^8.0.0 of the diff --git a/packages/reflectable_builder/lib/src/builder_implementation.dart b/packages/reflectable_builder/lib/src/builder_implementation.dart index 2fd93b59..7180dfe3 100644 --- a/packages/reflectable_builder/lib/src/builder_implementation.dart +++ b/packages/reflectable_builder/lib/src/builder_implementation.dart @@ -14,11 +14,10 @@ import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; -import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer/dart/element/type_system.dart'; -import 'package:analyzer/error/error.dart'; +import 'package:analyzer/diagnostic/diagnostic.dart'; import 'package:analyzer/error/listener.dart'; import 'package:analyzer/source/line_info.dart'; import 'package:analyzer/source/source.dart'; @@ -2474,7 +2473,7 @@ class _ReflectorDomain { /// [importCollector] is used to find the library prefixes needed in order /// to obtain values from other libraries. String _dynamicTypeCodeOfClass( - TypeDefiningElement typeDefiningElement, + Element typeDefiningElement, _ImportCollector importCollector, ) { DartType? type = typeDefiningElement is InterfaceElement @@ -6412,7 +6411,7 @@ Future _evaluateConstant( Source source = unitElement.source; var libraryElement = unitElement.element as LibraryElementImpl; - var errorListener = RecorderingErrorListener(); + var errorListener = RecordingDiagnosticListener(); var errorReporter = ErrorReporter(errorListener, source); var declaredVariables = DeclaredVariables(); // No variables. @@ -6440,12 +6439,18 @@ Future _evaluateConstant( Constant constant = visitor.evaluateAndReportInvalidConstant(expression); DartObjectImpl? dartObject = constant is DartObjectImpl ? constant : null; - if (errorListener.errors.isNotEmpty) { - var message = StringBuffer('Constant `$expression` has errors:\n'); - for (AnalysisError error in errorListener.errors) { - message.writeln(error); + if (errorListener.diagnostics.isNotEmpty) { + bool hasErrors = false; + final message = StringBuffer('Constant `$expression` has errors:\n'); + for (final diagnostic in errorListener.diagnostics) { + if (diagnostic.severity == Severity.error) { + hasErrors = true; + message.writeln(diagnostic); + } + } + if (hasErrors) { + _severe(message.toString()); } - _severe(message.toString()); } return dartObject; diff --git a/packages/reflectable_builder/pubspec.yaml b/packages/reflectable_builder/pubspec.yaml index 47cb7604..4134ed1a 100644 --- a/packages/reflectable_builder/pubspec.yaml +++ b/packages/reflectable_builder/pubspec.yaml @@ -1,5 +1,5 @@ name: reflectable_builder -version: 1.1.0 +version: 1.2.0 description: > Reflection support based on code generation, using 'capabilities' to specify which operations to support, on which objects. This is the @@ -9,19 +9,17 @@ environment: sdk: ^3.9.0 resolution: workspace dependencies: - analyzer: ^8.0.0 + analyzer: ^10.0.0 build: ^4.0.0 dart_style: ^3.0.0 pub_semver: ^2.2.0 path: ^1.9.0 - reflectable: '>=5.1.0 <5.2.0' + reflectable: '>=5.2.0 <5.3.0' dev_dependencies: - build_config: ^1.1.0 - build_resolvers: ^3.0.4 - build_runner: ^2.4.0 - build_runner_core: ^9.3.2 + build_config: ^1.2.0 + build_runner: ^2.10.0 glob: ^2.1.0 - lints: ^5.0.0 + lints: ^6.0.0 logging: ^1.2.0 package_config: ^2.1.0 source_span: ^1.10.0 diff --git a/packages/test_reflectable/test/exported_main_lib.dart b/packages/test_reflectable/test/exported_main_lib.dart deleted file mode 100644 index ed3a1d47..00000000 --- a/packages/test_reflectable/test/exported_main_lib.dart +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) 2015, the Dart Team. All rights reserved. Use of this -// source code is governed by a BSD-style license that can be found in -// the LICENSE file. - -// This file illustrates a peculiar situation: The `main` function which -// defines the behavior of the program 'exported_main_test.dart' is not -// declared in 'exported_main_test.dart', it is defined in this library. -// When this situation arises, i.e., when `main` is imported by the root -// library rather than being declared in the root library, the modifications -// which are otherwise needed in the root library must be applied to the -// library where the relevant `main` function is declared, i.e., this -// library. -// -// So we add an import of 'reflectable.dart' and of the generated code in -// 'exported_main_test.reflectable.dart', and add `initializeReflectable()` -// at the beginning of the body of `main`. -// -// Note the asymmetry: This library depends on the name of the root library -// of the program ('exported_main_test'), because the code generator stores -// the generated code in a file whose name is determined by the name of the -// file containing the root library. -// -// This again means that it is not possible to use this library as part of -// several different programs, all of which are using this library in order -// to "reuse the same `main`" (this file would then have to import a different -// '*.reflectable.dart' for each of those root libraries, but a library cannot -// contain different text "as seen from" different importing libraries). -// -// We recommend that such a design is simply avoided by adding a `main` -// function in each of those root libraries, renaming the `main` below to -// something else, say `myMain`, and then calling `myMain` from the newly -// added `main` functions (it doesn't even have to be renamed, but the name -// `main` may be confusing when it's never used as the entry point of a -// program): -// -// import 'sameNameAsThisFile.reflectable.dart'; -// ... -// main(String[] args) { -// initializeReflectable(); -// myMain(args); -// } -// -// In other words, this program shows that it is possible to import `main`, -// but it is not recommended, doesn't scale, and is easy to avoid. This is -// also the reason why README.md and other documentation does not discuss -// that situation. - -library test_reflectable.test.exported_main_lib; - -import 'package:test/test.dart'; -import 'package:reflectable/reflectable.dart'; -import 'exported_main_test.reflectable.dart'; - -class Reflector extends Reflectable { - const Reflector() : super(typeCapability); -} - -@Reflector() -class C {} - -void main() { - initializeReflectable(); - - test('exported main', () { - expect(const Reflector().canReflectType(C), true); - }); -} diff --git a/packages/test_reflectable/test/exported_main_test.dart b/packages/test_reflectable/test/exported_main_test.dart deleted file mode 100644 index 0dc0eb96..00000000 --- a/packages/test_reflectable/test/exported_main_test.dart +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) 2015, the Dart Team. All rights reserved. Use of this -// source code is governed by a BSD-style license that can be found in -// the LICENSE file. - -// Test that the transformation works with an exported main from another -// library. - -library test_reflectable.test.exported_main_test; - -export 'exported_main_lib.dart';