diff --git a/README.md b/README.md index bdd79718..4f0a6057 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,19 @@ +This repository provides the Dart packages `reflectable` and +`reflectable_builder`, along with a set of test cases and +examples in the repository `test_reflectable`. -This repository provides the Dart package `reflectable` along with a set of -test cases, `test_reflectable`. +## [reflectable](https://github.com/google/reflectable.dart/blob/master/packages/reflectable/README.md) -## [reflectable](https://github.com/google/reflectable.dart/blob/master/reflectable/README.md) +Support for implementing a large subset of the features offered by +'dart:mirrors' without relying on 'dart:mirrors' itself. Provides a system +based on capabilities to control the amount of reflection support. -Support for generating code that implements a large subset of the features -offered by 'dart:mirrors' without relying on 'dart:mirrors' itself. -Provides a system based on capabilities to control the amount of reflection -support. +## [reflectable_builder](https://github.com/google/reflectable.dart/blob/master/packages/reflectable_builder/README.md) -## [test_reflectable](https://github.com/google/reflectable.dart/blob/master/test_reflectable/README.md) +Support for generating the code that the package `reflectable` uses to provide +the reflection support described above. + +## [test_reflectable](https://github.com/google/reflectable.dart/blob/master/packages/test_reflectable/README.md) Used to test package `reflectable`. Also serves as a set of examples of how `reflectable` can be used. diff --git a/packages/reflectable/CHANGELOG.md b/packages/reflectable/CHANGELOG.md index 7b83f0b7..858b2253 100644 --- a/packages/reflectable/CHANGELOG.md +++ b/packages/reflectable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.2.1 + +- Fix bugs #354 and #325. + ## 5.2.0 - Upgrade reflectable to use analyzer ^10.0.0 and lints ^6.0.0. diff --git a/packages/reflectable/example/bin/example.dart b/packages/reflectable/example/bin/example.dart index 06dd352d..4d5998ea 100644 --- a/packages/reflectable/example/bin/example.dart +++ b/packages/reflectable/example/bin/example.dart @@ -22,7 +22,7 @@ class A { int argNamed(int x, int y, {int z = 42}) => x + y - z; int operator +(int x) => 42 + x; int operator [](int x) => 42 + x; - void operator []=(x, v) { + void operator []=(int x, int v) { f = x + v; } @@ -32,8 +32,9 @@ class A { int f = 0; static int noArguments() => 42; - static int oneArgument(x) => x - 42; - static int optionalArguments(x, y, [z = 0, w]) => x + y + z * 42; + static int oneArgument(int x) => x - 42; + static int optionalArguments(int x, int y, [int z = 0, int? w]) => + x + y + z * 42; static int namedArguments(int x, int y, {int z = 42}) => x + y - z; } diff --git a/packages/reflectable/pubspec.yaml b/packages/reflectable/pubspec.yaml index 321c7360..a80aacdf 100644 --- a/packages/reflectable/pubspec.yaml +++ b/packages/reflectable/pubspec.yaml @@ -1,5 +1,5 @@ name: reflectable -version: 5.2.0 +version: 5.2.1 description: > Reflection support based on code generation, using 'capabilities' to specify which operations to support, on which objects. This is the diff --git a/packages/reflectable_builder/CHANGELOG.md b/packages/reflectable_builder/CHANGELOG.md index d96c7b7c..42378eb9 100644 --- a/packages/reflectable_builder/CHANGELOG.md +++ b/packages/reflectable_builder/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.2.1 + +- Fix bugs #354 and #325. + ## 1.2.0 - Upgrade the code generator to use analyzer ^10.0.0 and lints 6.0.0. diff --git a/packages/reflectable_builder/example/example.dart b/packages/reflectable_builder/example/example.dart index 06dd352d..4d5998ea 100644 --- a/packages/reflectable_builder/example/example.dart +++ b/packages/reflectable_builder/example/example.dart @@ -22,7 +22,7 @@ class A { int argNamed(int x, int y, {int z = 42}) => x + y - z; int operator +(int x) => 42 + x; int operator [](int x) => 42 + x; - void operator []=(x, v) { + void operator []=(int x, int v) { f = x + v; } @@ -32,8 +32,9 @@ class A { int f = 0; static int noArguments() => 42; - static int oneArgument(x) => x - 42; - static int optionalArguments(x, y, [z = 0, w]) => x + y + z * 42; + static int oneArgument(int x) => x - 42; + static int optionalArguments(int x, int y, [int z = 0, int? w]) => + x + y + z * 42; static int namedArguments(int x, int y, {int z = 42}) => x + y - z; } diff --git a/packages/reflectable_builder/lib/src/builder_implementation.dart b/packages/reflectable_builder/lib/src/builder_implementation.dart index cf20dfca..9753acc1 100644 --- a/packages/reflectable_builder/lib/src/builder_implementation.dart +++ b/packages/reflectable_builder/lib/src/builder_implementation.dart @@ -4897,6 +4897,30 @@ class BuilderImplementation { } imports.sort(); + // Some "private" platform libraries are exported by public ones. To avoid + // the error caused by importing 'dart:_http', we transform it to 'dart:io'. + // Other cases are ambiguous and not handled. + final length = imports.length; + for (int index = 0; index < length; ++index) { + final import = imports[index]; + if (import.contains("'dart:_")) { + if (import.contains("'dart:_http'")) { + final rest = import.substring( + "import 'dart:_http' ".length, + import.length, + ); + imports[index] = "import 'dart:io' $rest"; + } else { + // TODO(eernst): Perhaps we can handle some of the remaining cases. + final match = RegExp(r"'dart:_.*'").firstMatch(import); + final String name = match != null + ? import.substring(match.start, match.end) + : import; + await _severe('Reference to an internal platform library: $name'); + } + } + } + var result = ''' // This file has been generated by the reflectable package. @@ -5575,6 +5599,7 @@ const Set sdkLibraryNames = { 'web_audio', 'web_gl', 'web_sql', + '_http', // Special case, redirected to 'dart:io'. }; // Helper for _extractMetadataCode. diff --git a/packages/reflectable_builder/pubspec.yaml b/packages/reflectable_builder/pubspec.yaml index 4134ed1a..379cac6b 100644 --- a/packages/reflectable_builder/pubspec.yaml +++ b/packages/reflectable_builder/pubspec.yaml @@ -1,5 +1,5 @@ name: reflectable_builder -version: 1.2.0 +version: 1.2.1 description: > Reflection support based on code generation, using 'capabilities' to specify which operations to support, on which objects. This is the diff --git a/packages/test_reflectable/test/substitute_http_test.dart b/packages/test_reflectable/test/substitute_http_test.dart new file mode 100644 index 00000000..9464822f --- /dev/null +++ b/packages/test_reflectable/test/substitute_http_test.dart @@ -0,0 +1,38 @@ +// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Test the special casing of declarations in 'dart:_http'. + +library test_reflectable.test.substitute_http_test; + +import 'dart:io'; + +@GlobalQuantifyCapability(r'\.Cookie$', reflector) +import 'package:reflectable/reflectable.dart'; + +import 'substitute_http_test.reflectable.dart'; + +class Reflector extends Reflectable { + const Reflector() + : super( + instanceInvokeCapability, + declarationsCapability, + superclassQuantifyCapability, + typeAnnotationQuantifyCapability, + ); +} + +const reflector = Reflector(); + +@reflector +class CookieHolder extends HttpException { + CookieHolder(super._); + final Cookie? cookie = null; +} + +void main() { + initializeReflectable(); + // Just checking that the program compiles, that is, it does not + // attempt to import `dart:_http`. +}